1

在我的应用程序中,我有 6 个按钮。在onCreate()中,我有一个startAnimation()将为按钮的外观执行动画。调用此方法后,我setOnclickListener()为每个按钮设置了 s。

我的代码onCreate()如下所示:

    startAnimations();

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

问题是:当我测试我的应用程序并且动画开始时,即使按钮尚未显示,我也可以单击任何按钮。我的意思是,我可以单击按钮位置,然后与该按钮相关的操作将开始。

我想强制按钮不响应点击,直到整个动画结束。

我可以这样做吗?

4

3 回答 3

4

为什么不禁用 onCreate 按钮或默认禁用按钮,然后在动画结束时启用它。

 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);

你怎么看?

于 2011-07-16T06:23:07.147 回答
1

您可以在调用动画按钮设置启用之前完成 false

b1.setEnabled(false);

然后调用startAnimations();然后完成您可以使用的动画b1.setEnabled(true);

像那样 ...

于 2011-07-16T06:22:41.240 回答
0

button.setClickable(false) 或 button.setOnClickListner(null) 也许?

也许设置这些,并注册一个 AnimationListener。看到这个。一旦 onAnimationEnd 被调用,button.setClickable(true) 和/或 button.setOnClickListener(this)。

于 2011-07-16T06:20:50.860 回答