我试图使用动画将图像从一个地方移动到另一个地方,但在将它移回原始位置后,如何将其停止到移动的位置本身。
发布于 2011-05-24 21:27:33
要让图像位于动画的最后位置,请尝试执行以下操作:
TranslationAnimation ta = new TranslateAnimation(fromX, toX, 0, 0);
ta.setDuration(1000);
ta.setFillAfter(true); // this will let the image in the last place of the Animation
imageView.startAnimation(ta);发布于 2015-03-31 15:29:53
动画完成后,使用方法setFillAfter(true),使最后一个动画状态保持不变:
如果fillAfter为true,则此动画执行的变换在完成时将持续。
Animation.setFillAfter/Before - Do they work/What are they for?
如果需要执行更具体的操作,还可以设置动画侦听器并在动画结束时移动对象:
animation1.setAnimationListener(new AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
}
@Override
public void onAnimationEnd(Animation animation) {
//change according to your needs
myView.setX(0);
}
@Override
public void onAnimationRepeat(Animation animation) { }
});发布于 2018-05-13 18:50:57
终于找到了一种变通的方法,正确的方法是setFillAfter(true),
如果你想在xml中定义你的动画,你应该这样做
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/decelerate_interpolator"
android:fillAfter="true">
<translate
android:fromXDelta="0%"
android:toXDelta="-100%"
android:duration="1000"/>
</set>您可以看到,我已经在set标记中定义了filterAfter="true“,如果您尝试
在翻译标签中定义它,它不会工作,可能是框架中的错误!!
然后在代码中
Animation anim = AnimationUtils.loadAnimation(this, R.anim.slide_out);
someView.startAnimation(anim);https://stackoverflow.com/questions/6110749
复制相似问题