我想用这样的方式动画一个imageView:(三角定义的角度符号)
通过下面的代码,我得到:
所以,完全不是我想要的!
有人知道如何解决这个问题吗?
谢谢!
这是我的代码:
float angle = 45f;
RotateAnimation rotateAnimation1 = new RotateAnimation(0, -angle,
Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
rotateAnimation1.setStartOffset(0);
rotateAnimation1.setDuration(2000);
rotateAnimation1.setInterpolator(new LinearInterpolator());
RotateAnimation rotateAnimation2 = new RotateAnimation(-angle, angle,
Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
// animationSet.addAnimation(rotateAnimation);
rotateAnimation2.setStartOffset(0);
rotateAnimation2.setDuration(4000);
rotateAnimation2.setInterpolator(new LinearInterpolator());
RotateAnimation rotateAnimation3 = new RotateAnimation(angle, -angle,
Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
rotateAnimation3.setStartOffset(4000);
rotateAnimation3.setDuration(4000);
rotateAnimation3.setInterpolator(new LinearInterpolator());
final AnimationSet animSet1 = new AnimationSet(true);
animSet1.setFillEnabled(true);
animSet1.addAnimation(rotateAnimation1);
final AnimationSet animSet2 = new AnimationSet(true);
// animSet2.setFillEnabled(true);
animSet2.addAnimation(rotateAnimation2);
animSet2.addAnimation(rotateAnimation3);
animSet1.setAnimationListener(new Animation.AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
}
@Override
public void onAnimationEnd(Animation animation) {
view.startAnimation(animSet2);
}
@Override
public void onAnimationRepeat(Animation animation) {
}
});
animSet2.setAnimationListener(new Animation.AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
}
@Override
public void onAnimationEnd(Animation animation) {
view.startAnimation(animSet2);
}
@Override
public void onAnimationRepeat(Animation animation) {
}
});
view.startAnimation(animSet1);发布于 2019-03-27 16:13:11
视图返回为零的原因是视图的旋转属性没有更改。您应该在第一个动画结束后将旋转设置为视图,或者使用默认情况下设置视图旋转的ObjectAnimator.ofFloat(imageview ,"rotation", 0f, 360f);。
发布于 2019-03-27 16:26:50
1.从0到-45的平滑旋转:倒转角符号和setFillAfter(true)因此视图保持结束动画位置
RotateAnimation rotateAnimation1 = new RotateAnimation(0, 45f,
Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
rotateAnimation1.setFillAfter(true); //This keeps view at animation ended position
rotateAnimation1.setStartOffset(0);
rotateAnimation1.setDuration(2000);
rotateAnimation1.setInterpolator(new LinearInterpolator());2.从-45到+45的平滑旋转:将动画开始角设置为0,因为视图已经旋转。
// Since view already is at -45 position due to rotateAnimation1.setFillAfter(true), now start point is 0 again
RotateAnimation rotateAnimation2 = new RotateAnimation(0, -90,
Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
rotateAnimation2.setFillAfter(true);
rotateAnimation2.setStartOffset(0);
rotateAnimation2.setDuration(4000);
rotateAnimation2.setInterpolator(new LinearInterpolator());其余步骤按照上面的逻辑简单明了。
https://stackoverflow.com/questions/55381490
复制相似问题