java
1public void aButtonClick(View view) { 2 3 Button button = (Button) findViewById(R.id.bbutton); 4 AlphaAnimation alphaAnimation = new AlphaAnimation(1.0f, 0.0f) 5 alphaAnimation.setDuration(2000); 6 alphaAnimation.setFillAfter(true); 7 button.startAnimation(alphaAnimation); 8} 9 10public void bButtonClick(View view) { 11 12 count++; 13 view.setBackgroundColor(Color.RED); 14 Log.d("count ", "" + count); 15}
Aボタンを押すとBボタンがフェードアウトして見えなくなる記述です。
Aボタンを押す前に、Bボタンを押すとボタン(背景)が赤く変更されますが
Aボタンを押した後、Bボタンを押すと何にもかわりません。
Bボタンのカウントはされてるので、クリックはされてるはずです。
これはアニメーションが続いた状態なのでしょうか?
どのようにしたらBボタンが生きるようになるのでしょうか?
改良後のコード
public void onButtonClick_A(View view) { Button button = (Button) findViewById(R.id.B_button); AlphaAnimation alphaAnimation = new AlphaAnimation(1.0f, 0.0f); alphaAnimation.setDuration(2000); alphaAnimation.setFillAfter(true); button.startAnimation(alphaAnimation); } public void onButtonClick_B(View view) { Button button = (Button) findViewById(R.id.B_button); AlphaAnimation alphaAnimation = new AlphaAnimation(0,0); alphaAnimation.setDuration(0); button.startAnimation(alphaAnimation); alphaAnimation.cancel(); view.setBackgroundColor(Color.RED); }
「アニメーションを止める」と回答があったので書き換えてみました
cancel()でアニメを止め、なんとか表示がされるようになったんですが、
ちょっと回りくどい感じで、他に改良の余地はあるのでしょうか?
また上の記述では、Bボタンを押すと一瞬Bボタンが消えて、そして現れます
これはアニメーションを止める処理がされてるので、そうなるのでしょうが
なにか方法はないでしょうか
他のやり方では
ClickListenerを使いAnimationListenerをセットし
@OverrideされるonAnimationEndでなんとかしようと考えたのですが
今回はbutton WidgetsのonClick内だけで処理できないだろうかと考えてます
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2015/12/20 01:58
2015/12/20 02:45
2015/12/21 02:14
2015/12/21 02:17