开发者

android animation problem

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(20开发者_Go百科0);
        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);

    }


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜