質問編集履歴
1
コード追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -2,4 +2,132 @@
|
|
2
2
|
|
3
3
|
|
4
4
|
|
5
|
+
```java
|
6
|
+
|
7
|
+
|
8
|
+
|
9
|
+
package com.example.test;
|
10
|
+
|
11
|
+
|
12
|
+
|
13
|
+
import
|
14
|
+
|
15
|
+
androidx.appcompat.app.AppCompatActivity;
|
16
|
+
|
17
|
+
|
18
|
+
|
19
|
+
import android.graphics.Canvas;
|
20
|
+
|
21
|
+
import android.graphics.Color;
|
22
|
+
|
23
|
+
import android.graphics.Point;
|
24
|
+
|
25
|
+
import android.os.Bundle;
|
26
|
+
|
27
|
+
import android.util.Log;
|
28
|
+
|
29
|
+
import android.view.ViewGroup;
|
30
|
+
|
31
|
+
import android.view.animation.Animation;
|
32
|
+
|
33
|
+
import android.view.animation.RotateAnimation;
|
34
|
+
|
35
|
+
import android.widget.Button;
|
36
|
+
|
37
|
+
import android.widget.LinearLayout;
|
38
|
+
|
39
|
+
import android.widget.TextView;
|
40
|
+
|
41
|
+
|
42
|
+
|
43
|
+
|
44
|
+
|
45
|
+
public class MainActivity extends AppCompatActivity {
|
46
|
+
|
47
|
+
MyView myView;
|
48
|
+
|
49
|
+
Button btn;
|
50
|
+
|
51
|
+
@Override
|
52
|
+
|
53
|
+
protected void onCreate(Bundle savedInstanceState) {
|
54
|
+
|
55
|
+
super.onCreate(savedInstanceState);
|
56
|
+
|
57
|
+
LinearLayout main=new LinearLayout(this);
|
58
|
+
|
59
|
+
LinearLayout.LayoutParams mainparam=new
|
60
|
+
|
61
|
+
LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
|
62
|
+
|
63
|
+
ViewGroup.LayoutParams.MATCH_PARENT);
|
64
|
+
|
65
|
+
|
66
|
+
|
67
|
+
main.setLayoutParams(mainparam);
|
68
|
+
|
69
|
+
main.setBackgroundColor(Color.WHITE);
|
70
|
+
|
71
|
+
main.setOrientation(LinearLayout.VERTICAL);
|
72
|
+
|
73
|
+
|
74
|
+
|
75
|
+
LinearLayout.LayoutParams btnparam=new
|
76
|
+
|
77
|
+
LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
|
78
|
+
|
79
|
+
ViewGroup.LayoutParams.MATCH_PARENT,1.0f);
|
80
|
+
|
81
|
+
|
82
|
+
|
83
|
+
myView = new MyView(this);
|
84
|
+
|
85
|
+
myView.setLayoutParams(btnparam);
|
86
|
+
|
87
|
+
|
88
|
+
|
89
|
+
btn=new Button(this);
|
90
|
+
|
91
|
+
btn.setLayoutParams(btnparam);
|
92
|
+
|
93
|
+
btn.setText(R.string.text4);
|
94
|
+
|
95
|
+
btn.setBackgroundColor(Color.BLACK);
|
96
|
+
|
97
|
+
|
98
|
+
|
99
|
+
btn.setOnClickListener(v->{
|
100
|
+
|
101
|
+
this.tap();
|
102
|
+
|
103
|
+
});
|
104
|
+
|
105
|
+
main.addView(myView);
|
106
|
+
|
107
|
+
main.addView(btn);
|
108
|
+
|
109
|
+
setContentView(main);
|
110
|
+
|
111
|
+
}
|
112
|
+
|
113
|
+
void tap(){
|
114
|
+
|
115
|
+
RotateAnimation ani =new RotateAnimation(0.0f,20000.0f,
|
116
|
+
|
117
|
+
Animation.RELATIVE_TO_SELF,0.5f,Animation.RELATIVE_TO_SELF,0.5f);
|
118
|
+
|
119
|
+
ani.setDuration(5000);
|
120
|
+
|
121
|
+
ani.setRepeatCount(0);
|
122
|
+
|
123
|
+
ani.setFillAfter(true);
|
124
|
+
|
125
|
+
myView.setAnimation(ani);
|
126
|
+
|
127
|
+
}
|
128
|
+
|
129
|
+
}
|
130
|
+
|
131
|
+
```
|
132
|
+
|
5
133
|
環境:Androidstdio
|