Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

android animation problem

Tags:

android

i wanna play scale(from 0 -> 1) animation on 6 balls , duration is 1000 ms on each ball.

and each animation have to wait the previous for 200ms.

ex :

anim1.start -> delay 200ms -> anim2.start (while anim1 is playing) -> ........

but i always got all 6 balls animations started at the same time , i don't know why , could

somebody tell me??

// show animation.
    public void showBallAnimation(View v) {

        LinearLayout ll = (LinearLayout) findViewById(R.id.ball_container);

        RelativeLayout rl;

        ScaleAnimation scaleAnim1 = new ScaleAnimation(0.0f, 1.0f, 0.0f, 1.0f);
        scaleAnim1.setDuration(500);
        scaleAnim1.setStartOffset(0);
        scaleAnim1.setFillAfter(true);
        rl = (RelativeLayout) ll.getChildAt(0);
        rl.setVisibility(View.VISIBLE);
        rl.startAnimation(scaleAnim1);

        ScaleAnimation scaleAnim2 = new ScaleAnimation(0.0f, 1.0f, 0.0f, 1.0f);
        scaleAnim2.setDuration(500);
        scaleAnim2.setStartOffset(200);
        scaleAnim2.setFillAfter(true);
        rl = (RelativeLayout) ll.getChildAt(1);
        rl.setVisibility(View.VISIBLE);
        rl.startAnimation(scaleAnim2);

        ScaleAnimation scaleAnim3 = new ScaleAnimation(0.0f, 1.0f, 0.0f, 1.0f);
        scaleAnim3.setDuration(500);
        scaleAnim3.setStartOffset(400);
        scaleAnim3.setFillAfter(true);
        rl = (RelativeLayout) ll.getChildAt(2);
        rl.setVisibility(View.VISIBLE);
        rl.startAnimation(scaleAnim3);

        // Animation anim4 =
        // AnimationUtils.loadAnimation(getApplicationContext(),
        // R.anim.ball_scale4);
        ScaleAnimation scaleAnim4 = new ScaleAnimation(0.0f, 1.0f, 0.0f, 1.0f);
        scaleAnim4.setDuration(500);
        scaleAnim4.setStartOffset(600);
        scaleAnim4.setFillAfter(true);
        rl = (RelativeLayout) ll.getChildAt(3);
        rl.setVisibility(View.VISIBLE);
        rl.startAnimation(scaleAnim4);

    }
like image 952
peterlawn Avatar asked Feb 20 '26 06:02

peterlawn


1 Answers

You should change r1.startAnimation(scaleAnimX) to r1.setAnimation(scaleAnimX)

Calling startAnimation() will start the Animation instantly, ignoring any time offset or start time.

Calling setAnimation() will take into account any time specifications.

like image 125
Matt M Avatar answered Feb 24 '26 11:02

Matt M



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!