【发布时间】:2013-03-05 16:31:22
【问题描述】:
最近几天在 android 中工作,我试图通过按下按钮来旋转箭头。使用 RotateAnimation 和:
setFillAfter(true);
箭头保持在最后的位置。 但是当我再次按下按钮时,箭头是开始从初始位置旋转,但是最后一次动画调用中的“上一个”箭头最终被“新”箭头重叠。所以我想我需要以某种方式重置/清除 setFillAfter 但我找不到方法。
我的代码是这样的:
//Animation start
float Xaxis=0.835366f;
float Yaxis=0.676692f;
RotateAnimation rotateAnimation1 = new RotateAnimation(0, 180,
Animation.RELATIVE_TO_SELF, Xaxis,Animation.RELATIVE_TO_SELF, Yaxis);
rotateAnimation1.setInterpolator(new LinearInterpolator());
rotateAnimation1.setDuration(2500);
rotateAnimation1.setRepeatCount(0);
image.startAnimation(rotateAnimation1);
rotateAnimation1.setAnimationListener(this);
@Override
public void onAnimationEnd(Animation animation) {
animation.setFillAfter(true);
}
任何想法都会很有用.. 我尝试过无效,将动画清除为图像,将 fillafter 设置为 false,重置动画但仍然相同。
【问题讨论】:
-
您必须自己更改 onAnimationEnd 中的箭头位置,是的!你设置了 setFillAfter(true);但动画后显示的位置不是箭头的实际位置
-
并调用 setAnimationListener(this);在开始动画之前
-
setFillBefore使箭头转到初始位置。我想停留在动画的结尾,当再次按下按钮时,整个动画都被移除/重置了之前的“帧”。 -
我不明白你的意思 Intathep,每次我按下按钮时,箭头都会启动(正确的)初始位置。为什么要换位置?