質問編集履歴
1
アニメーションを止める記述を追加しました
    
        title	
    CHANGED
    
    | @@ -1,1 +1,1 @@ | |
| 1 | 
            -
            ボタンクリックでアニメーション。その後 | 
| 1 | 
            +
            ボタンクリックでアニメーション。その後アニメを止めたい
         | 
    
        body	
    CHANGED
    
    | @@ -1,18 +1,18 @@ | |
| 1 1 | 
             
            ```java
         | 
| 2 2 | 
             
            public void aButtonClick(View view) {
         | 
| 3 3 |  | 
| 4 | 
            -
             | 
| 4 | 
            +
                Button button = (Button) findViewById(R.id.bbutton);
         | 
| 5 | 
            -
             | 
| 5 | 
            +
                AlphaAnimation alphaAnimation = new AlphaAnimation(1.0f, 0.0f)
         | 
| 6 | 
            -
             | 
| 6 | 
            +
                alphaAnimation.setDuration(2000);
         | 
| 7 | 
            -
             | 
| 7 | 
            +
                alphaAnimation.setFillAfter(true);
         | 
| 8 | 
            -
             | 
| 8 | 
            +
                button.startAnimation(alphaAnimation);
         | 
| 9 9 | 
             
            }
         | 
| 10 10 |  | 
| 11 11 | 
             
            public void bButtonClick(View view) {
         | 
| 12 12 |  | 
| 13 | 
            -
             | 
| 13 | 
            +
                count++;
         | 
| 14 | 
            -
             | 
| 14 | 
            +
                view.setBackgroundColor(Color.RED);
         | 
| 15 | 
            -
             | 
| 15 | 
            +
                Log.d("count ", "" + count);
         | 
| 16 16 | 
             
            }
         | 
| 17 17 | 
             
            ```
         | 
| 18 18 | 
             
            Aボタンを押すとBボタンがフェードアウトして見えなくなる記述です。
         | 
| @@ -22,4 +22,40 @@ | |
| 22 22 | 
             
            Bボタンのカウントはされてるので、クリックはされてるはずです。
         | 
| 23 23 |  | 
| 24 24 | 
             
            これはアニメーションが続いた状態なのでしょうか?
         | 
| 25 | 
            -
            どのようにしたらBボタンが生きるようになるのでしょうか?
         | 
| 25 | 
            +
            どのようにしたらBボタンが生きるようになるのでしょうか?
         | 
| 26 | 
            +
               
         | 
| 27 | 
            +
             | 
| 28 | 
            +
            >>>> 改良後のコード
         | 
| 29 | 
            +
            ```ここに言語を入力
         | 
| 30 | 
            +
            public void onButtonClick_A(View view) {
         | 
| 31 | 
            +
             | 
| 32 | 
            +
                Button button = (Button) findViewById(R.id.B_button);
         | 
| 33 | 
            +
                AlphaAnimation alphaAnimation = new AlphaAnimation(1.0f, 0.0f);
         | 
| 34 | 
            +
                alphaAnimation.setDuration(2000);
         | 
| 35 | 
            +
                alphaAnimation.setFillAfter(true);
         | 
| 36 | 
            +
                button.startAnimation(alphaAnimation);
         | 
| 37 | 
            +
            }
         | 
| 38 | 
            +
             | 
| 39 | 
            +
            public void onButtonClick_B(View view) {
         | 
| 40 | 
            +
             | 
| 41 | 
            +
                Button button = (Button) findViewById(R.id.B_button);
         | 
| 42 | 
            +
                AlphaAnimation alphaAnimation = new AlphaAnimation(0,0);
         | 
| 43 | 
            +
                alphaAnimation.setDuration(0);
         | 
| 44 | 
            +
                button.startAnimation(alphaAnimation);
         | 
| 45 | 
            +
                alphaAnimation.cancel();
         | 
| 46 | 
            +
             | 
| 47 | 
            +
                view.setBackgroundColor(Color.RED);
         | 
| 48 | 
            +
            }
         | 
| 49 | 
            +
            ```
         | 
| 50 | 
            +
            「アニメーションを止める」と回答があったので書き換えてみました
         | 
| 51 | 
            +
            cancel()でアニメを止め、なんとか表示がされるようになったんですが、
         | 
| 52 | 
            +
            ちょっと回りくどい感じで、他に改良の余地はあるのでしょうか?
         | 
| 53 | 
            +
             | 
| 54 | 
            +
            また上の記述では、Bボタンを押すと一瞬Bボタンが消えて、そして現れます
         | 
| 55 | 
            +
            これはアニメーションを止める処理がされてるので、そうなるのでしょうが
         | 
| 56 | 
            +
            なにか方法はないでしょうか
         | 
| 57 | 
            +
             | 
| 58 | 
            +
            他のやり方では
         | 
| 59 | 
            +
            ClickListenerを使いAnimationListenerをセットし
         | 
| 60 | 
            +
            @OverrideされるonAnimationEndでなんとかしようと考えたのですが
         | 
| 61 | 
            +
            今回はbutton WidgetsのonClick内だけで処理できないだろうかと考えてます
         | 
