如何启动的第一个动画列表结束后第二动画列表(how to start a second animat

2019-11-03 18:15发布

我想第一动画列表第一动画列表的末尾之后开始第二动画-list是(list_first):

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

<item
android:drawable="@drawable/f11"
android:duration="500"/>

<item
android:drawable="@drawable/delay"
android:duration="1000"/>

<item
android:drawable="@drawable/f12"
android:duration="500"/>

<item
android:drawable="@drawable/delay"
android:duration="1000"/>

</animation-list>

第二动画列表(list_second):

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

<item
android:drawable="@drawable/s21"
android:duration="500"/>

<item
android:drawable="@drawable/delay"
android:duration="1000"/>

<item
android:drawable="@drawable/s22"
android:duration="500"/>

<item
android:drawable="@drawable/delay"
android:duration="1000"/>

</animation-list>

现在如何开始在第一个列表的末尾第二动画列表?

ImageView img1;
TextView t1;

AnimationDrawable splashanimation;


@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
 super.onCreate(savedInstanceState);

    setContentView(R.layout.anim_layout);

    img1= (ImageView)findViewById(R.id.anim_imgview);
    img1.setBackgroundResource(R.drawable.list_first);
    splashanimation = (AnimationDrawable)img1.getBackground();
    splashanimation.start();

现在,在这里我没有得到什么做的? 如何开始对第一list..please建议结束第二动画列表

Answer 1:

尝试这个:

splashanimation = (AnimationDrawable)img1.getBackground();
splashanimation.start();

Handler handler = new Handler();
handler.postDelayed(new Runnable() {
                       public void run() {
                            //start your 2nd animation
                            //secondAnimation.start();
                       }
                    }, delay);//delay = the duration of your first animation, i think its 3000 in your case

或者你可以在一个结合2 XML动画:

combine_anim.xml文件

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

<item
android:drawable="@drawable/f11"
android:duration="500"/>

<item
android:drawable="@drawable/delay"
android:duration="1000"/>

<item
android:drawable="@drawable/f12"
android:duration="500"/>

<item
android:drawable="@drawable/delay"
android:duration="1000"/>

<item
android:drawable="@drawable/s21"
android:duration="500"/>

<item
android:drawable="@drawable/delay"
android:duration="1000"/>

<item
android:drawable="@drawable/s22"
android:duration="500"/>

<item
android:drawable="@drawable/delay"
android:duration="1000"/>

</animation-list>

并使用combine_anim.xml作为背景,而不是list_first.xml



文章来源: how to start a second animation-list after the end of first animation-list