【问题标题】:Problem with Android Animation?Android动画有问题吗?
【发布时间】:2011-07-16 06:10:48
【问题描述】:

在我的应用程序中,我有 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);

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

我想强制按钮在整个动画结束之前不响应点击。

我可以这样做吗?

【问题讨论】:

    标签: android android-animation android-button


    【解决方案1】:

    为什么不禁用按钮 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);
    

    你怎么看?

    【讨论】:

    • 效果很好!我将侦听器设置为startAnimation() 方法中的最后一个动画,效果很好。谢谢。
    【解决方案2】:

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

    b1.setEnabled(false);
    

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

    这样……

    【讨论】:

      【解决方案3】:

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

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

      【讨论】:

      • 这就是我的意思,注册一个 AnimationListener 以在动画完成时提醒您。完成后,允许再次单击按钮。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-09-03
      • 2021-10-13
      • 2016-03-29
      相关资源
      最近更新 更多