how to start a second animation-list after the end

2019-09-18 21:42发布

问题:

i want to start a second animation-list after the end of first animation-list first animation-list is(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>

Second animation-list is(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>

now how to start the second animation list at the end of first 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();

Now over here i am not getting what to do to ? how to start the second animation list on the end of first list..please suggest

回答1:

Try this:

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

Or you can combine the 2 xml animation in one:

combine_anim.xml file

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

And you use combine_anim.xml as background instead of list_first.xml