質問編集履歴
1
アニメーションを止める記述を追加しました
test
CHANGED
@@ -1 +1 @@
|
|
1
|
-
ボタンクリックでアニメーション。その後
|
1
|
+
ボタンクリックでアニメーション。その後アニメを止めたい
|
test
CHANGED
@@ -4,15 +4,15 @@
|
|
4
4
|
|
5
5
|
|
6
6
|
|
7
|
-
|
7
|
+
Button button = (Button) findViewById(R.id.bbutton);
|
8
8
|
|
9
|
-
|
9
|
+
AlphaAnimation alphaAnimation = new AlphaAnimation(1.0f, 0.0f)
|
10
10
|
|
11
|
-
|
11
|
+
alphaAnimation.setDuration(2000);
|
12
12
|
|
13
|
-
|
13
|
+
alphaAnimation.setFillAfter(true);
|
14
14
|
|
15
|
-
|
15
|
+
button.startAnimation(alphaAnimation);
|
16
16
|
|
17
17
|
}
|
18
18
|
|
@@ -22,11 +22,11 @@
|
|
22
22
|
|
23
23
|
|
24
24
|
|
25
|
-
|
25
|
+
count++;
|
26
26
|
|
27
|
-
|
27
|
+
view.setBackgroundColor(Color.RED);
|
28
28
|
|
29
|
-
|
29
|
+
Log.d("count ", "" + count);
|
30
30
|
|
31
31
|
}
|
32
32
|
|
@@ -47,3 +47,75 @@
|
|
47
47
|
これはアニメーションが続いた状態なのでしょうか?
|
48
48
|
|
49
49
|
どのようにしたらBボタンが生きるようになるのでしょうか?
|
50
|
+
|
51
|
+
|
52
|
+
|
53
|
+
|
54
|
+
|
55
|
+
>>>> 改良後のコード
|
56
|
+
|
57
|
+
```ここに言語を入力
|
58
|
+
|
59
|
+
public void onButtonClick_A(View view) {
|
60
|
+
|
61
|
+
|
62
|
+
|
63
|
+
Button button = (Button) findViewById(R.id.B_button);
|
64
|
+
|
65
|
+
AlphaAnimation alphaAnimation = new AlphaAnimation(1.0f, 0.0f);
|
66
|
+
|
67
|
+
alphaAnimation.setDuration(2000);
|
68
|
+
|
69
|
+
alphaAnimation.setFillAfter(true);
|
70
|
+
|
71
|
+
button.startAnimation(alphaAnimation);
|
72
|
+
|
73
|
+
}
|
74
|
+
|
75
|
+
|
76
|
+
|
77
|
+
public void onButtonClick_B(View view) {
|
78
|
+
|
79
|
+
|
80
|
+
|
81
|
+
Button button = (Button) findViewById(R.id.B_button);
|
82
|
+
|
83
|
+
AlphaAnimation alphaAnimation = new AlphaAnimation(0,0);
|
84
|
+
|
85
|
+
alphaAnimation.setDuration(0);
|
86
|
+
|
87
|
+
button.startAnimation(alphaAnimation);
|
88
|
+
|
89
|
+
alphaAnimation.cancel();
|
90
|
+
|
91
|
+
|
92
|
+
|
93
|
+
view.setBackgroundColor(Color.RED);
|
94
|
+
|
95
|
+
}
|
96
|
+
|
97
|
+
```
|
98
|
+
|
99
|
+
「アニメーションを止める」と回答があったので書き換えてみました
|
100
|
+
|
101
|
+
cancel()でアニメを止め、なんとか表示がされるようになったんですが、
|
102
|
+
|
103
|
+
ちょっと回りくどい感じで、他に改良の余地はあるのでしょうか?
|
104
|
+
|
105
|
+
|
106
|
+
|
107
|
+
また上の記述では、Bボタンを押すと一瞬Bボタンが消えて、そして現れます
|
108
|
+
|
109
|
+
これはアニメーションを止める処理がされてるので、そうなるのでしょうが
|
110
|
+
|
111
|
+
なにか方法はないでしょうか
|
112
|
+
|
113
|
+
|
114
|
+
|
115
|
+
他のやり方では
|
116
|
+
|
117
|
+
ClickListenerを使いAnimationListenerをセットし
|
118
|
+
|
119
|
+
@OverrideされるonAnimationEndでなんとかしようと考えたのですが
|
120
|
+
|
121
|
+
今回はbutton WidgetsのonClick内だけで処理できないだろうかと考えてます
|