回答編集履歴
1
コード
test
CHANGED
@@ -3,3 +3,99 @@
|
|
3
3
|
アニメーションされていればボタンのidを保持させます.(状態の数値は,それぞれ異なれば何でもいい)
|
4
4
|
|
5
5
|
そしてonClickでその状態をチェックし,押されたボタンのidと違う時だけ数値変更とアニメーションをすればいいのではないでしょうか.
|
6
|
+
|
7
|
+
|
8
|
+
|
9
|
+
ちょっと元のコードが危ない感じがした(2つのボタンを同じ変数で扱っている)のと,アニメーションのメソッドが2つあったのが気になったので,全体を書いてみました.
|
10
|
+
|
11
|
+
```lang-java
|
12
|
+
|
13
|
+
public class MainActivity extends Activity implements View.OnClickListener{
|
14
|
+
|
15
|
+
int mode = 0;
|
16
|
+
|
17
|
+
Button btnStart, btnStart1;
|
18
|
+
|
19
|
+
ImageView image;
|
20
|
+
|
21
|
+
|
22
|
+
|
23
|
+
public void onCreate(Bundle savedInstanceState){
|
24
|
+
|
25
|
+
super.onCreate(savedInstanceState);
|
26
|
+
|
27
|
+
setContentView(R.layout.activity_main);
|
28
|
+
|
29
|
+
image = (ImageView) findViewById(R.id.image);
|
30
|
+
|
31
|
+
|
32
|
+
|
33
|
+
btnStart = (Button) findViewById(R.id.start);
|
34
|
+
|
35
|
+
btnStart.setOnClickListener(this);
|
36
|
+
|
37
|
+
|
38
|
+
|
39
|
+
btnStart1 = (Button) findViewById(R.id.start1);
|
40
|
+
|
41
|
+
btnStart1.setOnClickListener(this);
|
42
|
+
|
43
|
+
}
|
44
|
+
|
45
|
+
|
46
|
+
|
47
|
+
public void onClick(View v){
|
48
|
+
|
49
|
+
int id = v.getId();
|
50
|
+
|
51
|
+
if(id != mode){
|
52
|
+
|
53
|
+
mode = id;
|
54
|
+
|
55
|
+
switch(id){
|
56
|
+
|
57
|
+
case R.id.start:
|
58
|
+
|
59
|
+
startColorAnimation(image, 0xFFffffff, 0xFF000000);
|
60
|
+
|
61
|
+
break;
|
62
|
+
|
63
|
+
case R.id.start1:
|
64
|
+
|
65
|
+
startColorAnimation(image, 0xfff53b6d, 0xFF000000);
|
66
|
+
|
67
|
+
break;
|
68
|
+
|
69
|
+
}
|
70
|
+
|
71
|
+
}
|
72
|
+
|
73
|
+
}
|
74
|
+
|
75
|
+
|
76
|
+
|
77
|
+
|
78
|
+
|
79
|
+
public void startColorAnimation(View view, int colorStart, int colorEnd){
|
80
|
+
|
81
|
+
|
82
|
+
|
83
|
+
ValueAnimator colorAnim = ObjectAnimator.ofInt(
|
84
|
+
|
85
|
+
view, "backgroundColor", colorStart, colorEnd);
|
86
|
+
|
87
|
+
colorAnim.setDuration(2000);
|
88
|
+
|
89
|
+
colorAnim.setEvaluator(new ArgbEvaluator());
|
90
|
+
|
91
|
+
colorAnim.setRepeatCount(100);
|
92
|
+
|
93
|
+
colorAnim.setRepeatMode(ValueAnimator.REVERSE);
|
94
|
+
|
95
|
+
colorAnim.start();
|
96
|
+
|
97
|
+
}
|
98
|
+
|
99
|
+
}
|
100
|
+
|
101
|
+
```
|