2017-02-15 102 views

回答

2

试试这个。

ObjectAnimator animation = ObjectAnimator.ofFloat(yourImageView, "rotationX", 0.0f, 90f); 
     animation.setDuration(1000); 
     animation.setRepeatCount(ObjectAnimator.INFINITE); 
     animation.setRepeatMode(ObjectAnimator.REVERSE); 
     animation.setInterpolator(new AccelerateDecelerateInterpolator()); 
     animation.start(); 
+0

但旋转完整的图像,我想图像修复 –

+0

的底部则是图像分割成两个和旋转第一部分。 –

+0

我做到了,但如何使两个旋转我没有得到它 –

3

答案很简单,您必须设置视图的支点,以便在旋转时可以通过轴旋转视图。 (在你的情况,这个代码将保持视图底部相同,动画视图顶部就像你在视频显示)

enter image description here

根据图像如果杆底盒是25percentage图像高度,那么你必须计算图像的轴旋转25%。

View v = findViewById(R.id.animate_view); 
    v.setOnClickListener(new View.OnClickListener() { 
     @Override 
     public void onClick(final View v) { 
      int percentageHeightOfBox = 25; 
      int height = v.getMeasuredHeight(); 
      v.setPivotX(v.getMeasuredWidth()/2); 
      v.setPivotY(height - ((height * percentageHeightOfBox)/100)); 
      ValueAnimator animator = ValueAnimator.ofFloat(0.0f, 90f); 
      animator.setDuration(1000); 
      animator.setRepeatCount(ObjectAnimator.INFINITE); 
      animator.setRepeatMode(ObjectAnimator.REVERSE); 
      animator.setInterpolator(new AccelerateDecelerateInterpolator()); 
      animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { 
       @Override 
       public void onAnimationUpdate(ValueAnimator animation) { 
        float rotate = Float.parseFloat(animation.getAnimatedValue().toString()); 
        v.setRotationX(rotate); 
       } 
      }); 
      animator.start(); 
     } 
    }); 
+0

不工作,我想图像修复 –

+1

其工作的底部。我测试了这个代码。图像或视图正在回退。休息你可以用相同的代码/想法做。 –

+0

@DharaPatel可能你没有准确地尝试过代码,代码工作得很好。请尝试使用枢轴广告价值动画制作人的确切代码。 –