我试图在布局上从左向右移动图像,但不是通过拖动。我希望它在发生某些事情时自动运行。所以,我找到了这样的动画:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/accelerate_interpolator" >
<translate
android:duration="1000"
android:fromXDelta="0"
android:toXDelta="200"
android:fillEnabled="true"
android:fillAfter="true" />
</set>
但问题是我找不到如何让它停在那里!直接就回去了。有什么建议吗?
这是我的 Java 代码:
public void onClick(View v) {
runOnRight(this, image);
}
static Animation runOnRight(Activity ctx, View target) {
Animation animation = AnimationUtils.loadAnimation(ctx,
R.anim.slide_left_to_right);
target.startAnimation(animation);
return animation;
}
最佳答案
在动画设置 xml 中将 FillAfter
设置为 true
关于android - 如何停止通过动画移动的图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9193627/