Android 如何停止通过动画移动的图像?

Android 如何停止通过动画移动的图像?,android,animation,Android,Animation,我尝试在布局上从左向右移动图像,但不是通过拖动。我希望它在发生事情时自动运行。所以,我发现了这样一个动画: <?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android" android:interpolator="@android:anim/accelerate_interpolator" > <translate

我尝试在布局上从左向右移动图像,但不是通过拖动。我希望它在发生事情时自动运行。所以,我发现了这样一个动画:

<?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>

在动画集xml中将
FillAfter
设置为
true
使用FillAfter=“true”字段,该字段将在末尾停止。
与下面一样。

当启动回调时,您可以使用设置新视图位置。View.layout调用为视图指定大小和位置。有关更多信息,请参阅文档

我根据您的建议添加了这个android:fillAfter=“true”,但仍然没有到此为止。
 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;
    }