开发者

Problem with Android Animation?

In my application I have 6 buttons. In onCreate(), I have a startAnimation() which will perform animation for the appearance of the buttons. After the call to this method I have setOnclickListener()s for each button.

My code in the onCreate() looks like this:

    startAnimations();

    b1.setOnClickListener(this);
    b2.setOnClickListener(this);
    b3.setOnClickListener(this);
    b4.setOnClickListener(this);
    b5.setOnClickListener(this);
    b6.setOnClickListener(this);

The Problem is: when I tested my application and while the animation starts, I can click any button even if the button didn't show yet. I mean, I ca开发者_如何学编程n click in the button place and the action related to that button will start.

I want to force the buttons to NOT respond to the clicks until the whole animation is over.

Can I do that?


Why don't you disable your buttons onCreate or by defaut and then when animations ends, enable it.

 findViewById(R.id.button1).setEnable(false);
 findViewById(R.id.button1).setEnable(false);
 ....   
 final RelativeLayout l = (RelativeLayout) findViewById(R.id.group_band);
 Animation a = new TranslateAnimation(0, 0, -100, 0);
 a.setDuration(200);
 a.setAnimationListener(new AnimationListener() {

                public void onAnimationEnd(Animation animation) {
                    findViewById(R.id.button1).setEnable(true);
                    findViewById(R.id.button2).setEnable(true);
                                             ....
                }

                public void onAnimationRepeat(Animation animation) {

                }

                public void onAnimationStart(Animation animation) {

                }

            });

 l.startAnimation(l);

What do you think?


You can done with before call animation button set enabled false

b1.setEnabled(false);

then call startAnimations(); then complete on animation you can do with b1.setEnabled(true);

like that ...


button.setClickable(false) or button.setOnClickListner(null) maybe?

Maybe set those, and register an AnimationListener. See this. Once onAnimationEnd is called, button.setClickable(true) and/or button.setOnClickListener(this).

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜