动画中的延迟(TranslateAnimation)

ymo*_*tov 15 android android-animation translate-animation

有没有办法Animation暂停半秒?

我正在尝试使用TranslateAnimationAPI 制作无限动画.所以,我使用RepeatCountas Infinite.我还注意到,有一种setStartOffset(...)方法可以涵盖我想要延迟启动动画的情况.但是,我无法在每次"重启"之前找到延迟的方法.由于动画会发生无限次,每次动画重新启动时我都需要延迟.

有任何想法吗?

谢谢!!

Spi*_*pau 12

这是一个例子:

首先是带有我们想要动画的图像的布局(main.xml):

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/ic_launcher" />

</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

下一个是动画.放在res/anim中,称为anim_img.xml.该文件包含android:startOffset ="500"(以毫秒为单位)的翻译动画.这将设置每次动画开始时使用的偏移量:

<?xml version="1.0" encoding="utf-8"?>
<set>

    <translate
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:duration="1000"
        android:fromXDelta="0%"
        android:fromYDelta="0%"
        android:toXDelta="0%"
        android:toYDelta="100%"
        android:zAdjustment="top" 
        android:repeatCount="infinite"
        android:startOffset="500"/>

</set>
Run Code Online (Sandbox Code Playgroud)

最后但并非最不重要的 - 活动.哪个开始动画:

public class StackOverflowActivity extends Activity {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        ImageView iv_icon = (ImageView) findViewById(R.id.imageView1);

        Animation a = AnimationUtils.loadAnimation(this, R.anim.anim_img);
        a.setFillAfter(true);
        a.reset();

        iv_icon.startAnimation(a);
    }
}
Run Code Online (Sandbox Code Playgroud)

干杯,保罗


Pao*_*a G 9

要在每次重启之间实现x毫秒的暂停:

myAnimation.setAnimationListener(new AnimationListener(){

        @Override
        public void onAnimationStart(Animation arg0) {
        }
        @Override
        public void onAnimationEnd(Animation animation) {
        }

        @Override
        public void onAnimationRepeat(Animation animation) {
            myAnimation.setStartOffset(x);
        }

    });
Run Code Online (Sandbox Code Playgroud)