2011-07-16 70 views
1

在我的應用程序中,我有6個按鈕。在onCreate(),我有一個startAnimation()這將執行按鈕的外觀動畫。在對這個方法的調用之後,我對每個按鈕都有setOnclickListener()Android動畫問題?

我在onCreate()代碼如下所示:

startAnimations(); 

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

的問題是:當我測試我的應用程序,而動畫開始時,我可以點擊任何按鈕,即使該按鈕沒有顯示然而。我的意思是,我可以點擊按鈕位置,並且與該按鈕相關的操作將開始。

我想迫使按鈕不響應點擊,直到整個動畫結束。

我可以那樣做嗎?

回答

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

您怎麼看?

+0

工程太棒了!我將偵聽器設置爲'startAnimation()'方法中的最後一個動畫,並且效果很好。謝謝。 – iTurki

0

button.setClickable(false)or button.setOnClickListner(null)也許?

也許設置這些,並註冊一個AnimationListener。見this。一旦onAnimationEnd被調用,button.setClickable(true)和/或button.setOnClickListener(this)。

+0

那就是我說的,註冊一個AnimationListener來在動畫完成時提醒你。完成後,再次點擊按鈕。 – Jack

1

您可以啓用虛假

b1.setEnabled(false); 

然後調用startAnimations();然後完整的動畫,你可以用b1.setEnabled(true);

這樣做之前調用動畫按鈕設置完成...