2012-02-08 98 views
2

我正在尝试将图像从左向右移动到布局上,但不是通过拖动。发生什么事情时我想让它自动运行。所以,我发现了这样一个动画:如何停止通过动画移动的图像?

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

回答

1

设置FillAftertrue动画中的组XML

+0

我在您的建议中添加了此android:fillAfter =“true”,但它仍然不止于此。 – yahya 2012-02-08 13:05:56

0

使用字段FillAfter = “真”,这将停止在终点。 就像下面。