2011-07-16 9 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

なぜドン」ボタンを無効にしたり、アニメーションが終了したら、有効にします。

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)またはbutton.setOnClickListner(null)?

これらを設定し、AnimationListenerを登録することがあります。 thisを参照してください。 onAnimationEndが呼び出されると、button.setClickable(true)またはbutton.setOnClickListener(this)が呼び出されます。

あなたが

b1.setEnabled(false); 

その後、あなたがそのようなb1.setEnabled(true);

で行うことができますアニメーションの完全なそしてstartAnimations();を呼び出す有効falseの前にコールアニメーションボタンセットで行うことができます

+0

アニメーションが完了すると、あなたに警告するためにAnimationListenerを登録します。ボタンをクリックすると、再びボタンをクリックできます。 – Jack

関連する問題