質問編集履歴
4
コード正確なものに修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -8,9 +8,95 @@
|
|
8
8
|
|
9
9
|
|
10
10
|
|
11
|
-
```Java
|
12
11
|
|
12
|
+
|
13
|
+
※申し訳ありません 今のコードに変更する前に投稿したコードが、一部のコード情報を消す際に不手際によりエラーコードとは異なる誤ったコードを投稿してしまいました。
|
14
|
+
|
15
|
+
このコードは別プロジェクトで再作成したものでありますのでこれが本物です。
|
16
|
+
|
17
|
+
お騒がせしてすみません。
|
18
|
+
|
19
|
+
|
20
|
+
|
21
|
+
|
22
|
+
|
23
|
+
↓MainActivity
|
24
|
+
|
25
|
+
```java
|
26
|
+
|
27
|
+
|
28
|
+
|
13
|
-
package com.
|
29
|
+
package developer.shion.com.tests;
|
30
|
+
|
31
|
+
|
32
|
+
|
33
|
+
import android.support.v7.app.AppCompatActivity;
|
34
|
+
|
35
|
+
import android.os.Bundle;
|
36
|
+
|
37
|
+
|
38
|
+
|
39
|
+
public class MainActivity extends AppCompatActivity {
|
40
|
+
|
41
|
+
|
42
|
+
|
43
|
+
@Override
|
44
|
+
|
45
|
+
protected void onCreate(Bundle savedInstanceState) {
|
46
|
+
|
47
|
+
super.onCreate(savedInstanceState);
|
48
|
+
|
49
|
+
setContentView(R.layout.activity_main);
|
50
|
+
|
51
|
+
|
52
|
+
|
53
|
+
}
|
54
|
+
|
55
|
+
}
|
56
|
+
|
57
|
+
```
|
58
|
+
|
59
|
+
|
60
|
+
|
61
|
+
activity_main
|
62
|
+
|
63
|
+
```xml
|
64
|
+
|
65
|
+
<?xml version="1.0" encoding="utf-8"?>
|
66
|
+
|
67
|
+
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
68
|
+
|
69
|
+
xmlns:app="http://schemas.android.com/apk/res-auto"
|
70
|
+
|
71
|
+
xmlns:tools="http://schemas.android.com/tools"
|
72
|
+
|
73
|
+
android:layout_width="match_parent"
|
74
|
+
|
75
|
+
android:layout_height="match_parent"
|
76
|
+
|
77
|
+
tools:context=".MainActivity">
|
78
|
+
|
79
|
+
|
80
|
+
|
81
|
+
<developer.shion.com.tests.CustomView
|
82
|
+
|
83
|
+
android:layout_width="wrap_content"
|
84
|
+
|
85
|
+
android:layout_height="wrap_content" />
|
86
|
+
|
87
|
+
</FrameLayout>
|
88
|
+
|
89
|
+
```
|
90
|
+
|
91
|
+
|
92
|
+
|
93
|
+
|
94
|
+
|
95
|
+
CustomView
|
96
|
+
|
97
|
+
```java
|
98
|
+
|
99
|
+
package developer.shion.com.tests;
|
14
100
|
|
15
101
|
|
16
102
|
|
@@ -28,67 +114,55 @@
|
|
28
114
|
|
29
115
|
import android.widget.ImageView;
|
30
116
|
|
117
|
+
import android.widget.LinearLayout;
|
31
118
|
|
32
119
|
|
33
|
-
public class CustomViewExample extends FrameLayout{
|
34
120
|
|
121
|
+
public class CustomView extends FrameLayout {
|
122
|
+
|
35
|
-
public CustomView
|
123
|
+
public CustomView(Context context, @Nullable AttributeSet attributeSet){
|
36
124
|
|
37
125
|
super(context,attributeSet);
|
38
126
|
|
39
|
-
ImageView imageView=new ImageView(context);
|
127
|
+
final ImageView imageView=new ImageView(context);
|
40
128
|
|
41
|
-
imageView.set
|
129
|
+
imageView.setImageResource(R.drawable.ic_launcher_background);
|
42
130
|
|
43
|
-
imageView.setImageResource(R.drawable.image);
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
131
|
+
imageView.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
|
48
|
-
|
49
|
-
objectAnimator.setDuration(1000);
|
50
132
|
|
51
133
|
addView(imageView);
|
52
134
|
|
53
|
-
|
54
135
|
|
136
|
+
|
137
|
+
new Thread(new Runnable() {
|
138
|
+
|
139
|
+
@Override
|
140
|
+
|
141
|
+
public void run() {
|
142
|
+
|
143
|
+
try {
|
144
|
+
|
145
|
+
Thread.sleep(1500);
|
146
|
+
|
147
|
+
} catch (InterruptedException e) {
|
148
|
+
|
149
|
+
e.printStackTrace();
|
150
|
+
|
151
|
+
}
|
152
|
+
|
153
|
+
ObjectAnimator objectAnimator=ObjectAnimator.ofFloat(imageView,"translationX",0,500);
|
154
|
+
|
155
|
+
objectAnimator.setDuration(1000);
|
156
|
+
|
55
|
-
objectAnimator.start();
|
157
|
+
objectAnimator.start();
|
158
|
+
|
159
|
+
}
|
160
|
+
|
161
|
+
}).start();
|
56
162
|
|
57
163
|
}
|
58
164
|
|
59
165
|
}
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
```
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
```xml
|
68
|
-
|
69
|
-
<?xml version="1.0" encoding="utf-8"?>
|
70
|
-
|
71
|
-
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
72
|
-
|
73
|
-
xmlns:app="http://schemas.android.com/apk/res-auto"
|
74
|
-
|
75
|
-
android:layout_width="match_parent"
|
76
|
-
|
77
|
-
android:layout_height="match_parent"
|
78
|
-
|
79
|
-
app:layout_behavior="@string/appbar_scrolling_view_behavior">
|
80
|
-
|
81
|
-
<CustomViewExample
|
82
|
-
|
83
|
-
android:layout_width="match_parent"
|
84
|
-
|
85
|
-
android:layout_height="match_parent"/>
|
86
|
-
|
87
|
-
</FrameLayout>
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
166
|
|
93
167
|
```
|
94
168
|
|
@@ -98,9 +172,9 @@
|
|
98
172
|
|
99
173
|
```Log
|
100
174
|
|
101
|
-
08-0
|
175
|
+
08-10 10:30:02.854 19111-19158/developer.shion.com.tests E/AndroidRuntime: FATAL EXCEPTION: Thread-4
|
102
176
|
|
103
|
-
Process: com.
|
177
|
+
Process: developer.shion.com.tests, PID: 19111
|
104
178
|
|
105
179
|
android.util.AndroidRuntimeException: Animators may only be run on Looper threads
|
106
180
|
|
@@ -110,83 +184,7 @@
|
|
110
184
|
|
111
185
|
at android.animation.ObjectAnimator.start(ObjectAnimator.java:852)
|
112
186
|
|
113
|
-
at com.abcdefg.******.CustomViewExample$2.run(CustomViewExample.java:94)
|
114
|
-
|
115
|
-
at java.lang.Thread.run(Thread.java:764)
|
116
|
-
|
117
|
-
at com.
|
187
|
+
at developer.shion.com.tests.CustomView$1.run(CustomView.java:30)
|
118
|
-
|
119
|
-
at java.lang.Thread.run(Thread.java:764)
|
120
|
-
|
121
|
-
at com.abcdefg.******.CustomViewExample$1.run(CustomViewExample.java:62)
|
122
|
-
|
123
|
-
at java.lang.Thread.run(Thread.java:764)
|
124
|
-
|
125
|
-
at com.abcdefg.******.CustomViewExample$1.run(CustomViewExample.java:62)
|
126
|
-
|
127
|
-
at java.lang.Thread.run(Thread.java:764)
|
128
|
-
|
129
|
-
at com.abcdefg.******.CustomViewExample$1.run(CustomViewExample.java:62)
|
130
|
-
|
131
|
-
at java.lang.Thread.run(Thread.java:764)
|
132
|
-
|
133
|
-
at com.abcdefg.******.CustomViewExample$1.run(CustomViewExample.java:62)
|
134
|
-
|
135
|
-
at java.lang.Thread.run(Thread.java:764)
|
136
|
-
|
137
|
-
at com.abcdefg.******.CustomViewExample$1.run(CustomViewExample.java:62)
|
138
|
-
|
139
|
-
at java.lang.Thread.run(Thread.java:764)
|
140
|
-
|
141
|
-
at com.abcdefg.******.CustomViewExample$1.run(CustomViewExample.java:62)
|
142
|
-
|
143
|
-
at java.lang.Thread.run(Thread.java:764)
|
144
|
-
|
145
|
-
at com.abcdefg.******.CustomViewExample$1.run(CustomViewExample.java:62)
|
146
|
-
|
147
|
-
at java.lang.Thread.run(Thread.java:764)
|
148
|
-
|
149
|
-
at com.abcdefg.******.CustomViewExample$1.run(CustomViewExample.java:62)
|
150
|
-
|
151
|
-
at java.lang.Thread.run(Thread.java:764)
|
152
|
-
|
153
|
-
at com.abcdefg.******.CustomViewExample$1.run(CustomViewExample.java:62)
|
154
|
-
|
155
|
-
at java.lang.Thread.run(Thread.java:764)
|
156
|
-
|
157
|
-
at com.abcdefg.******.CustomViewExample$1.run(CustomViewExample.java:62)
|
158
|
-
|
159
|
-
at java.lang.Thread.run(Thread.java:764)
|
160
|
-
|
161
|
-
at com.abcdefg.******.CustomViewExample$1.run(CustomViewExample.java:62)
|
162
|
-
|
163
|
-
at java.lang.Thread.run(Thread.java:764)
|
164
|
-
|
165
|
-
at com.abcdefg.******.CustomViewExample$1.run(CustomViewExample.java:62)
|
166
|
-
|
167
|
-
at java.lang.Thread.run(Thread.java:764)
|
168
|
-
|
169
|
-
at com.abcdefg.******.CustomViewExample$1.run(CustomViewExample.java:62)
|
170
|
-
|
171
|
-
at java.lang.Thread.run(Thread.java:764)
|
172
|
-
|
173
|
-
at com.abcdefg.******.CustomViewExample$1.run(CustomViewExample.java:62)
|
174
|
-
|
175
|
-
at java.lang.Thread.run(Thread.java:764)
|
176
|
-
|
177
|
-
at com.abcdefg.******.CustomViewExample$1.run(CustomViewExample.java:62)
|
178
|
-
|
179
|
-
at java.lang.Thread.run(Thread.java:764)
|
180
|
-
|
181
|
-
at com.abcdefg.******.CustomViewExample$1.run(CustomViewExample.java:62)
|
182
|
-
|
183
|
-
at java.lang.Thread.run(Thread.java:764)
|
184
|
-
|
185
|
-
at com.abcdefg.******.CustomViewExample$1.run(CustomViewExample.java:62)
|
186
|
-
|
187
|
-
at java.lang.Thread.run(Thread.java:764)
|
188
|
-
|
189
|
-
at com.abcdefg.******.CustomViewExample$1.run(CustomViewExample.java:62)
|
190
188
|
|
191
189
|
at java.lang.Thread.run(Thread.java:764)
|
192
190
|
|
3
ミスの修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -10,7 +10,7 @@
|
|
10
10
|
|
11
11
|
```Java
|
12
12
|
|
13
|
-
package
|
13
|
+
package com.abcdefg.******;
|
14
14
|
|
15
15
|
|
16
16
|
|
2
質問内容のコードの誤り修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -78,7 +78,7 @@
|
|
78
78
|
|
79
79
|
app:layout_behavior="@string/appbar_scrolling_view_behavior">
|
80
80
|
|
81
|
-
<CustomView
|
81
|
+
<CustomViewExample
|
82
82
|
|
83
83
|
android:layout_width="match_parent"
|
84
84
|
|
1
質問内容のコードの誤り
test
CHANGED
File without changes
|
test
CHANGED
@@ -30,9 +30,9 @@
|
|
30
30
|
|
31
31
|
|
32
32
|
|
33
|
-
public class CustomView extends FrameLayout{
|
33
|
+
public class CustomViewExample extends FrameLayout{
|
34
34
|
|
35
|
-
public CustomView(Context context, @Nullable AttributeSet attributeSet){
|
35
|
+
public CustomViewExample(Context context, @Nullable AttributeSet attributeSet){
|
36
36
|
|
37
37
|
super(context,attributeSet);
|
38
38
|
|