質問編集履歴
3
修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -38,6 +38,10 @@
|
|
38
38
|
|
39
39
|
※実際のソースコードを下記へ追記致します。
|
40
40
|
|
41
|
+
■コード
|
42
|
+
|
43
|
+
【activity_sub.xml】
|
44
|
+
|
41
45
|
```
|
42
46
|
|
43
47
|
<?xml version="1.0" encoding="utf-8"?>
|
@@ -148,9 +152,7 @@
|
|
148
152
|
|
149
153
|
```
|
150
154
|
|
151
|
-
|
155
|
+
|
152
|
-
|
153
|
-
【activity_sub.xml】
|
154
156
|
|
155
157
|
|
156
158
|
|
2
ソース修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -38,123 +38,127 @@
|
|
38
38
|
|
39
39
|
※実際のソースコードを下記へ追記致します。
|
40
40
|
|
41
|
-
|
41
|
+
```
|
42
|
+
|
43
|
+
<?xml version="1.0" encoding="utf-8"?>
|
44
|
+
|
45
|
+
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
46
|
+
|
47
|
+
android:layout_width="match_parent"
|
48
|
+
|
49
|
+
android:layout_height="match_parent">
|
50
|
+
|
51
|
+
|
52
|
+
|
53
|
+
<ImageView
|
54
|
+
|
55
|
+
android:id="@+id/background_sub"
|
56
|
+
|
57
|
+
android:layout_width="match_parent"
|
58
|
+
|
59
|
+
android:layout_height="match_parent"
|
60
|
+
|
61
|
+
android:layout_centerHorizontal="true"
|
62
|
+
|
63
|
+
android:layout_centerVertical="true"
|
64
|
+
|
65
|
+
android:scaleType="centerCrop"
|
66
|
+
|
67
|
+
android:src="@drawable/yukacopy" />
|
68
|
+
|
69
|
+
|
70
|
+
|
71
|
+
<Button
|
72
|
+
|
73
|
+
android:id="@+id/button"
|
74
|
+
|
75
|
+
android:layout_width="30dp"
|
76
|
+
|
77
|
+
android:layout_height="30dp"
|
78
|
+
|
79
|
+
android:layout_alignParentEnd="true"
|
80
|
+
|
81
|
+
android:layout_alignParentRight="true"
|
82
|
+
|
83
|
+
android:background="#00FF0000" />
|
84
|
+
|
85
|
+
|
86
|
+
|
87
|
+
<ImageView
|
88
|
+
|
89
|
+
android:id="@+id/airplain"
|
90
|
+
|
91
|
+
android:layout_width="180dp"
|
92
|
+
|
93
|
+
android:layout_height="150dp"
|
94
|
+
|
95
|
+
android:layout_alignParentTop="true"
|
96
|
+
|
97
|
+
android:layout_toLeftOf="@+id/button"
|
98
|
+
|
99
|
+
android:layout_toStartOf="@+id/button"
|
100
|
+
|
101
|
+
android:src="@drawable/airplain" />
|
102
|
+
|
103
|
+
|
104
|
+
|
105
|
+
<Button
|
106
|
+
|
107
|
+
android:id="@+id/button1"
|
108
|
+
|
109
|
+
android:layout_width="30dp"
|
110
|
+
|
111
|
+
android:layout_height="30dp"
|
112
|
+
|
113
|
+
android:layout_alignParentBottom="true"
|
114
|
+
|
115
|
+
android:layout_centerHorizontal="true"
|
116
|
+
|
117
|
+
android:layout_marginBottom="43dp"
|
118
|
+
|
119
|
+
android:background="#00FF0000" />
|
120
|
+
|
121
|
+
|
122
|
+
|
123
|
+
<ImageView
|
124
|
+
|
125
|
+
android:id="@+id/heri"
|
126
|
+
|
127
|
+
android:layout_width="190dp"
|
128
|
+
|
129
|
+
android:layout_height="160dp"
|
130
|
+
|
131
|
+
android:layout_alignParentBottom="true"
|
132
|
+
|
133
|
+
android:layout_marginLeft="27dp"
|
134
|
+
|
135
|
+
android:layout_marginStart="27dp"
|
136
|
+
|
137
|
+
android:layout_toEndOf="@+id/button1"
|
138
|
+
|
139
|
+
android:layout_toRightOf="@+id/button1"
|
140
|
+
|
141
|
+
android:src="@drawable/heri" />
|
142
|
+
|
143
|
+
|
144
|
+
|
145
|
+
</RelativeLayout>
|
146
|
+
|
147
|
+
|
148
|
+
|
149
|
+
```
|
42
150
|
|
43
151
|
■コード
|
44
152
|
|
45
153
|
【activity_sub.xml】
|
46
154
|
|
47
|
-
<?xml version="1.0" encoding="utf-8"?>
|
48
|
-
|
49
|
-
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
50
|
-
|
51
|
-
android:layout_width="match_parent"
|
52
|
-
|
53
|
-
android:layout_height="match_parent">
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
<ImageView
|
58
|
-
|
59
|
-
android:id="@+id/background_sub"
|
60
|
-
|
61
|
-
android:layout_width="match_parent"
|
62
|
-
|
63
|
-
android:layout_height="match_parent"
|
64
|
-
|
65
|
-
android:layout_centerHorizontal="true"
|
66
|
-
|
67
|
-
android:layout_centerVertical="true"
|
68
|
-
|
69
|
-
android:scaleType="centerCrop"
|
70
|
-
|
71
|
-
android:src="@drawable/yukacopy" />
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
<Button
|
76
|
-
|
77
|
-
android:id="@+id/button"
|
78
|
-
|
79
|
-
android:layout_width="30dp"
|
80
|
-
|
81
|
-
android:layout_height="30dp"
|
82
|
-
|
83
|
-
android:layout_alignParentEnd="true"
|
84
|
-
|
85
|
-
android:layout_alignParentRight="true"
|
86
|
-
|
87
|
-
android:background="#00FF0000" />
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
<ImageView
|
92
|
-
|
93
|
-
android:id="@+id/airplain"
|
94
|
-
|
95
|
-
android:layout_width="180dp"
|
96
|
-
|
97
|
-
android:layout_height="150dp"
|
98
|
-
|
99
|
-
android:layout_alignParentTop="true"
|
100
|
-
|
101
|
-
android:layout_toLeftOf="@+id/button"
|
102
|
-
|
103
|
-
android:layout_toStartOf="@+id/button"
|
104
|
-
|
105
|
-
android:src="@drawable/airplain" />
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
<Button
|
110
|
-
|
111
|
-
android:id="@+id/button1"
|
112
|
-
|
113
|
-
android:layout_width="30dp"
|
114
|
-
|
115
|
-
android:layout_height="30dp"
|
116
|
-
|
117
|
-
android:layout_alignParentBottom="true"
|
118
|
-
|
119
|
-
android:layout_centerHorizontal="true"
|
120
|
-
|
121
|
-
android:layout_marginBottom="43dp"
|
122
|
-
|
123
|
-
android:background="#00FF0000" />
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
<ImageView
|
128
|
-
|
129
|
-
android:id="@+id/heri"
|
130
|
-
|
131
|
-
android:layout_width="190dp"
|
132
|
-
|
133
|
-
android:layout_height="160dp"
|
134
|
-
|
135
|
-
android:layout_alignParentBottom="true"
|
136
|
-
|
137
|
-
android:layout_marginLeft="27dp"
|
138
|
-
|
139
|
-
android:layout_marginStart="27dp"
|
140
|
-
|
141
|
-
android:layout_toEndOf="@+id/button1"
|
142
|
-
|
143
|
-
android:layout_toRightOf="@+id/button1"
|
144
|
-
|
145
|
-
android:src="@drawable/heri" />
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
</RelativeLayout>
|
150
|
-
|
151
155
|
|
152
156
|
|
153
157
|
|
154
158
|
|
155
159
|
【SubActivity.java】
|
156
160
|
|
157
|
-
|
161
|
+
```
|
158
162
|
|
159
163
|
public class SubActivity extends Activity {
|
160
164
|
|
@@ -271,3 +275,5 @@
|
|
271
275
|
|
272
276
|
|
273
277
|
}
|
278
|
+
|
279
|
+
```
|
1
ソースコード追記しました
test
CHANGED
File without changes
|
test
CHANGED
@@ -33,3 +33,241 @@
|
|
33
33
|
|
34
34
|
|
35
35
|
何でも構いませんのでご指摘お願いいたします。
|
36
|
+
|
37
|
+
|
38
|
+
|
39
|
+
※実際のソースコードを下記へ追記致します。
|
40
|
+
|
41
|
+
|
42
|
+
|
43
|
+
■コード
|
44
|
+
|
45
|
+
【activity_sub.xml】
|
46
|
+
|
47
|
+
<?xml version="1.0" encoding="utf-8"?>
|
48
|
+
|
49
|
+
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
50
|
+
|
51
|
+
android:layout_width="match_parent"
|
52
|
+
|
53
|
+
android:layout_height="match_parent">
|
54
|
+
|
55
|
+
|
56
|
+
|
57
|
+
<ImageView
|
58
|
+
|
59
|
+
android:id="@+id/background_sub"
|
60
|
+
|
61
|
+
android:layout_width="match_parent"
|
62
|
+
|
63
|
+
android:layout_height="match_parent"
|
64
|
+
|
65
|
+
android:layout_centerHorizontal="true"
|
66
|
+
|
67
|
+
android:layout_centerVertical="true"
|
68
|
+
|
69
|
+
android:scaleType="centerCrop"
|
70
|
+
|
71
|
+
android:src="@drawable/yukacopy" />
|
72
|
+
|
73
|
+
|
74
|
+
|
75
|
+
<Button
|
76
|
+
|
77
|
+
android:id="@+id/button"
|
78
|
+
|
79
|
+
android:layout_width="30dp"
|
80
|
+
|
81
|
+
android:layout_height="30dp"
|
82
|
+
|
83
|
+
android:layout_alignParentEnd="true"
|
84
|
+
|
85
|
+
android:layout_alignParentRight="true"
|
86
|
+
|
87
|
+
android:background="#00FF0000" />
|
88
|
+
|
89
|
+
|
90
|
+
|
91
|
+
<ImageView
|
92
|
+
|
93
|
+
android:id="@+id/airplain"
|
94
|
+
|
95
|
+
android:layout_width="180dp"
|
96
|
+
|
97
|
+
android:layout_height="150dp"
|
98
|
+
|
99
|
+
android:layout_alignParentTop="true"
|
100
|
+
|
101
|
+
android:layout_toLeftOf="@+id/button"
|
102
|
+
|
103
|
+
android:layout_toStartOf="@+id/button"
|
104
|
+
|
105
|
+
android:src="@drawable/airplain" />
|
106
|
+
|
107
|
+
|
108
|
+
|
109
|
+
<Button
|
110
|
+
|
111
|
+
android:id="@+id/button1"
|
112
|
+
|
113
|
+
android:layout_width="30dp"
|
114
|
+
|
115
|
+
android:layout_height="30dp"
|
116
|
+
|
117
|
+
android:layout_alignParentBottom="true"
|
118
|
+
|
119
|
+
android:layout_centerHorizontal="true"
|
120
|
+
|
121
|
+
android:layout_marginBottom="43dp"
|
122
|
+
|
123
|
+
android:background="#00FF0000" />
|
124
|
+
|
125
|
+
|
126
|
+
|
127
|
+
<ImageView
|
128
|
+
|
129
|
+
android:id="@+id/heri"
|
130
|
+
|
131
|
+
android:layout_width="190dp"
|
132
|
+
|
133
|
+
android:layout_height="160dp"
|
134
|
+
|
135
|
+
android:layout_alignParentBottom="true"
|
136
|
+
|
137
|
+
android:layout_marginLeft="27dp"
|
138
|
+
|
139
|
+
android:layout_marginStart="27dp"
|
140
|
+
|
141
|
+
android:layout_toEndOf="@+id/button1"
|
142
|
+
|
143
|
+
android:layout_toRightOf="@+id/button1"
|
144
|
+
|
145
|
+
android:src="@drawable/heri" />
|
146
|
+
|
147
|
+
|
148
|
+
|
149
|
+
</RelativeLayout>
|
150
|
+
|
151
|
+
|
152
|
+
|
153
|
+
|
154
|
+
|
155
|
+
【SubActivity.java】
|
156
|
+
|
157
|
+
|
158
|
+
|
159
|
+
public class SubActivity extends Activity {
|
160
|
+
|
161
|
+
|
162
|
+
|
163
|
+
ImageView airplain;
|
164
|
+
|
165
|
+
ImageView heri;
|
166
|
+
|
167
|
+
|
168
|
+
|
169
|
+
@Override
|
170
|
+
|
171
|
+
protected void onCreate(Bundle savedInstanceState) {
|
172
|
+
|
173
|
+
super.onCreate(savedInstanceState);
|
174
|
+
|
175
|
+
setContentView(R.layout.activity_sub);
|
176
|
+
|
177
|
+
|
178
|
+
|
179
|
+
airplain = (ImageView) findViewById(R.id.airplain);
|
180
|
+
|
181
|
+
heri = (ImageView) findViewById(R.id.heri);
|
182
|
+
|
183
|
+
|
184
|
+
|
185
|
+
final View.OnTouchListener moving = new View.OnTouchListener() {
|
186
|
+
|
187
|
+
|
188
|
+
|
189
|
+
private float downX;
|
190
|
+
|
191
|
+
private float downY;
|
192
|
+
|
193
|
+
|
194
|
+
|
195
|
+
private int downLeftMargin;
|
196
|
+
|
197
|
+
private int downTopMargin;
|
198
|
+
|
199
|
+
|
200
|
+
|
201
|
+
@Override
|
202
|
+
|
203
|
+
public boolean onTouch(View v, MotionEvent event) {
|
204
|
+
|
205
|
+
|
206
|
+
|
207
|
+
final ViewGroup.MarginLayoutParams param =
|
208
|
+
|
209
|
+
(ViewGroup.MarginLayoutParams) v.getLayoutParams();
|
210
|
+
|
211
|
+
if (event.getAction() == MotionEvent.ACTION_DOWN) {
|
212
|
+
|
213
|
+
|
214
|
+
|
215
|
+
downX = event.getRawX();
|
216
|
+
|
217
|
+
downY = event.getRawY();
|
218
|
+
|
219
|
+
|
220
|
+
|
221
|
+
downLeftMargin = param.leftMargin;
|
222
|
+
|
223
|
+
downTopMargin = param.topMargin;
|
224
|
+
|
225
|
+
v.bringToFront();
|
226
|
+
|
227
|
+
|
228
|
+
|
229
|
+
return true;
|
230
|
+
|
231
|
+
} else if (event.getAction() == MotionEvent.ACTION_MOVE) {
|
232
|
+
|
233
|
+
|
234
|
+
|
235
|
+
param.leftMargin = downLeftMargin + (int) (event.getRawX() - downX);
|
236
|
+
|
237
|
+
param.topMargin = downTopMargin + (int) (event.getRawY() - downY);
|
238
|
+
|
239
|
+
|
240
|
+
|
241
|
+
v.layout(param.leftMargin, param.topMargin, param.leftMargin + v.getWidth(), param.topMargin + v.getHeight());
|
242
|
+
|
243
|
+
v.bringToFront();
|
244
|
+
|
245
|
+
return true;
|
246
|
+
|
247
|
+
} else if (event.getAction() == MotionEvent.ACTION_UP) {
|
248
|
+
|
249
|
+
|
250
|
+
|
251
|
+
} else if (event.getAction() == MotionEvent.ACTION_CANCEL) {
|
252
|
+
|
253
|
+
|
254
|
+
|
255
|
+
}
|
256
|
+
|
257
|
+
return false;
|
258
|
+
|
259
|
+
}
|
260
|
+
|
261
|
+
};
|
262
|
+
|
263
|
+
airplain.setOnTouchListener(moving);
|
264
|
+
|
265
|
+
heri.setOnTouchListener(moving);
|
266
|
+
|
267
|
+
}
|
268
|
+
|
269
|
+
}
|
270
|
+
|
271
|
+
|
272
|
+
|
273
|
+
}
|