質問編集履歴
2
ソースコードの追記
test
CHANGED
File without changes
|
test
CHANGED
@@ -32,7 +32,7 @@
|
|
32
32
|
|
33
33
|
なぞっているのに、画面が飯能しないことについて、どんな原因が考えられるでしょうか・・??
|
34
34
|
|
35
|
-
|
35
|
+
↓MainActivity.java
|
36
36
|
|
37
37
|
```java
|
38
38
|
|
@@ -40,6 +40,126 @@
|
|
40
40
|
|
41
41
|
|
42
42
|
|
43
|
+
import android.os.Bundle;
|
44
|
+
|
45
|
+
import android.support.design.widget.FloatingActionButton;
|
46
|
+
|
47
|
+
import android.support.design.widget.Snackbar;
|
48
|
+
|
49
|
+
import android.support.v7.app.AppCompatActivity;
|
50
|
+
|
51
|
+
import android.support.v7.widget.Toolbar;
|
52
|
+
|
53
|
+
import android.view.View;
|
54
|
+
|
55
|
+
import android.view.Menu;
|
56
|
+
|
57
|
+
import android.view.MenuItem;
|
58
|
+
|
59
|
+
|
60
|
+
|
61
|
+
public class MainActivity extends AppCompatActivity {
|
62
|
+
|
63
|
+
|
64
|
+
|
65
|
+
@Override
|
66
|
+
|
67
|
+
protected void onCreate(Bundle savedInstanceState) {
|
68
|
+
|
69
|
+
super.onCreate(savedInstanceState);
|
70
|
+
|
71
|
+
setContentView(R.layout.activity_main);
|
72
|
+
|
73
|
+
|
74
|
+
|
75
|
+
|
76
|
+
|
77
|
+
Toolbar toolbar = findViewById(R.id.toolbar);
|
78
|
+
|
79
|
+
setSupportActionBar(toolbar);
|
80
|
+
|
81
|
+
|
82
|
+
|
83
|
+
FloatingActionButton fab = findViewById(R.id.fab);
|
84
|
+
|
85
|
+
fab.setOnClickListener(new View.OnClickListener() {
|
86
|
+
|
87
|
+
@Override
|
88
|
+
|
89
|
+
public void onClick(View view) {
|
90
|
+
|
91
|
+
//Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG).setAction("Action", null).show();
|
92
|
+
|
93
|
+
PaintView paintView = (PaintView)findViewById(R.id.view);
|
94
|
+
|
95
|
+
paintView.clear();
|
96
|
+
|
97
|
+
}
|
98
|
+
|
99
|
+
});
|
100
|
+
|
101
|
+
}
|
102
|
+
|
103
|
+
|
104
|
+
|
105
|
+
@Override
|
106
|
+
|
107
|
+
public boolean onCreateOptionsMenu(Menu menu) {
|
108
|
+
|
109
|
+
// Inflate the menu; this adds items to the action bar if it is present.
|
110
|
+
|
111
|
+
getMenuInflater().inflate(R.menu.menu_main, menu);
|
112
|
+
|
113
|
+
return true;
|
114
|
+
|
115
|
+
}
|
116
|
+
|
117
|
+
|
118
|
+
|
119
|
+
@Override
|
120
|
+
|
121
|
+
public boolean onOptionsItemSelected(MenuItem item) {
|
122
|
+
|
123
|
+
// Handle action bar item clicks here. The action bar will
|
124
|
+
|
125
|
+
// automatically handle clicks on the Home/Up button, so long
|
126
|
+
|
127
|
+
// as you specify a parent activity in AndroidManifest.xml.
|
128
|
+
|
129
|
+
int id = item.getItemId();
|
130
|
+
|
131
|
+
|
132
|
+
|
133
|
+
//noinspection SimplifiableIfStatement
|
134
|
+
|
135
|
+
if (id == R.id.action_settings) {
|
136
|
+
|
137
|
+
return true;
|
138
|
+
|
139
|
+
}
|
140
|
+
|
141
|
+
|
142
|
+
|
143
|
+
return super.onOptionsItemSelected(item);
|
144
|
+
|
145
|
+
}
|
146
|
+
|
147
|
+
}
|
148
|
+
|
149
|
+
|
150
|
+
|
151
|
+
```
|
152
|
+
|
153
|
+
↓PaintView.java
|
154
|
+
|
155
|
+
```java
|
156
|
+
|
157
|
+
|
158
|
+
|
159
|
+
package com.example.paintview;
|
160
|
+
|
161
|
+
|
162
|
+
|
43
163
|
import android.content.Context;
|
44
164
|
|
45
165
|
import android.graphics.Canvas;
|
@@ -66,16 +186,24 @@
|
|
66
186
|
|
67
187
|
|
68
188
|
|
189
|
+
|
190
|
+
|
191
|
+
|
192
|
+
|
69
193
|
public PaintView(Context context) {
|
70
194
|
|
71
195
|
this(context, null);
|
72
196
|
|
197
|
+
|
198
|
+
|
73
199
|
}
|
74
200
|
|
75
201
|
|
76
202
|
|
77
203
|
public PaintView(Context context, AttributeSet attrs) {
|
78
204
|
|
205
|
+
|
206
|
+
|
79
207
|
super(context, attrs);
|
80
208
|
|
81
209
|
path = new Path();
|
@@ -162,150 +290,12 @@
|
|
162
290
|
|
163
291
|
}
|
164
292
|
|
165
|
-
|
166
|
-
|
167
|
-
```java
|
168
|
-
|
169
|
-
package com.example.paintview;
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
import android.content.Context;
|
174
|
-
|
175
|
-
import android.graphics.Canvas;
|
176
|
-
|
177
|
-
import android.graphics.Paint;
|
178
|
-
|
179
|
-
import android.graphics.Path;
|
180
|
-
|
181
|
-
import android.util.AttributeSet;
|
182
|
-
|
183
|
-
import android.view.MotionEvent;
|
184
|
-
|
185
|
-
import android.view.View;
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
public class PaintView extends View {
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
private Paint paint;
|
194
|
-
|
195
|
-
private Path path;
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
public PaintView(Context context) {
|
204
|
-
|
205
|
-
this(context, null);
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
}
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
public PaintView(Context context, AttributeSet attrs) {
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
super(context, attrs);
|
218
|
-
|
219
|
-
path = new Path();
|
220
|
-
|
221
|
-
paint = new Paint();
|
222
|
-
|
223
|
-
paint.setColor(0xFF000000);
|
224
|
-
|
225
|
-
paint.setStyle(Paint.Style.STROKE);
|
226
|
-
|
227
|
-
paint.setStrokeJoin(Paint.Join.ROUND);
|
228
|
-
|
229
|
-
paint.setStrokeCap(Paint.Cap.ROUND);
|
230
|
-
|
231
|
-
paint.setStrokeWidth(10);
|
232
|
-
|
233
|
-
}
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
@Override
|
238
|
-
|
239
|
-
protected void onDraw(Canvas canvas) {
|
240
|
-
|
241
|
-
canvas.drawPath(path, paint);
|
242
|
-
|
243
|
-
}
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
@Override
|
248
|
-
|
249
|
-
public boolean onTouchEvent(MotionEvent event) {
|
250
|
-
|
251
|
-
float x = event.getX();
|
252
|
-
|
253
|
-
float y = event.getY();
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
switch (event.getAction()) {
|
258
|
-
|
259
|
-
case MotionEvent.ACTION_DOWN:
|
260
|
-
|
261
|
-
path.moveTo(x, y);
|
262
|
-
|
263
|
-
invalidate();
|
264
|
-
|
265
|
-
break;
|
266
|
-
|
267
|
-
case MotionEvent.ACTION_MOVE:
|
268
|
-
|
269
|
-
path.lineTo(x, y);
|
270
|
-
|
271
|
-
invalidate();
|
272
|
-
|
273
|
-
break;
|
274
|
-
|
275
|
-
case MotionEvent.ACTION_UP:
|
276
|
-
|
277
|
-
path.lineTo(x, y);
|
278
|
-
|
279
|
-
invalidate();
|
280
|
-
|
281
|
-
break;
|
282
|
-
|
283
|
-
}
|
284
|
-
|
285
|
-
return true;
|
286
|
-
|
287
|
-
}
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
public void clear(){
|
292
|
-
|
293
|
-
path.reset();
|
294
|
-
|
295
|
-
invalidate();
|
296
|
-
|
297
|
-
}
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
}
|
302
|
-
|
303
|
-
|
304
|
-
|
305
293
|
```
|
306
294
|
|
307
295
|
|
308
296
|
|
297
|
+
↓activity_main.xml
|
298
|
+
|
309
299
|
```xml
|
310
300
|
|
311
301
|
<?xml version="1.0" encoding="utf-8"?>
|
@@ -382,6 +372,8 @@
|
|
382
372
|
|
383
373
|
|
384
374
|
|
375
|
+
↓content_main/xml
|
376
|
+
|
385
377
|
```xml
|
386
378
|
|
387
379
|
<?xml version="1.0" encoding="utf-8"?>
|
1
ソースコードの追記
test
CHANGED
File without changes
|
test
CHANGED
@@ -164,4 +164,262 @@
|
|
164
164
|
|
165
165
|
|
166
166
|
|
167
|
+
```java
|
168
|
+
|
169
|
+
package com.example.paintview;
|
170
|
+
|
171
|
+
|
172
|
+
|
173
|
+
import android.content.Context;
|
174
|
+
|
175
|
+
import android.graphics.Canvas;
|
176
|
+
|
177
|
+
import android.graphics.Paint;
|
178
|
+
|
179
|
+
import android.graphics.Path;
|
180
|
+
|
181
|
+
import android.util.AttributeSet;
|
182
|
+
|
183
|
+
import android.view.MotionEvent;
|
184
|
+
|
185
|
+
import android.view.View;
|
186
|
+
|
187
|
+
|
188
|
+
|
189
|
+
public class PaintView extends View {
|
190
|
+
|
191
|
+
|
192
|
+
|
193
|
+
private Paint paint;
|
194
|
+
|
195
|
+
private Path path;
|
196
|
+
|
197
|
+
|
198
|
+
|
199
|
+
|
200
|
+
|
201
|
+
|
202
|
+
|
203
|
+
public PaintView(Context context) {
|
204
|
+
|
205
|
+
this(context, null);
|
206
|
+
|
207
|
+
|
208
|
+
|
209
|
+
}
|
210
|
+
|
211
|
+
|
212
|
+
|
213
|
+
public PaintView(Context context, AttributeSet attrs) {
|
214
|
+
|
215
|
+
|
216
|
+
|
217
|
+
super(context, attrs);
|
218
|
+
|
219
|
+
path = new Path();
|
220
|
+
|
221
|
+
paint = new Paint();
|
222
|
+
|
223
|
+
paint.setColor(0xFF000000);
|
224
|
+
|
225
|
+
paint.setStyle(Paint.Style.STROKE);
|
226
|
+
|
227
|
+
paint.setStrokeJoin(Paint.Join.ROUND);
|
228
|
+
|
229
|
+
paint.setStrokeCap(Paint.Cap.ROUND);
|
230
|
+
|
231
|
+
paint.setStrokeWidth(10);
|
232
|
+
|
233
|
+
}
|
234
|
+
|
235
|
+
|
236
|
+
|
237
|
+
@Override
|
238
|
+
|
239
|
+
protected void onDraw(Canvas canvas) {
|
240
|
+
|
241
|
+
canvas.drawPath(path, paint);
|
242
|
+
|
243
|
+
}
|
244
|
+
|
245
|
+
|
246
|
+
|
247
|
+
@Override
|
248
|
+
|
249
|
+
public boolean onTouchEvent(MotionEvent event) {
|
250
|
+
|
251
|
+
float x = event.getX();
|
252
|
+
|
253
|
+
float y = event.getY();
|
254
|
+
|
255
|
+
|
256
|
+
|
257
|
+
switch (event.getAction()) {
|
258
|
+
|
259
|
+
case MotionEvent.ACTION_DOWN:
|
260
|
+
|
261
|
+
path.moveTo(x, y);
|
262
|
+
|
263
|
+
invalidate();
|
264
|
+
|
265
|
+
break;
|
266
|
+
|
267
|
+
case MotionEvent.ACTION_MOVE:
|
268
|
+
|
269
|
+
path.lineTo(x, y);
|
270
|
+
|
271
|
+
invalidate();
|
272
|
+
|
273
|
+
break;
|
274
|
+
|
275
|
+
case MotionEvent.ACTION_UP:
|
276
|
+
|
277
|
+
path.lineTo(x, y);
|
278
|
+
|
279
|
+
invalidate();
|
280
|
+
|
281
|
+
break;
|
282
|
+
|
283
|
+
}
|
284
|
+
|
285
|
+
return true;
|
286
|
+
|
287
|
+
}
|
288
|
+
|
289
|
+
|
290
|
+
|
291
|
+
public void clear(){
|
292
|
+
|
293
|
+
path.reset();
|
294
|
+
|
295
|
+
invalidate();
|
296
|
+
|
297
|
+
}
|
298
|
+
|
299
|
+
|
300
|
+
|
301
|
+
}
|
302
|
+
|
303
|
+
|
304
|
+
|
167
305
|
```
|
306
|
+
|
307
|
+
|
308
|
+
|
309
|
+
```xml
|
310
|
+
|
311
|
+
<?xml version="1.0" encoding="utf-8"?>
|
312
|
+
|
313
|
+
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
314
|
+
|
315
|
+
xmlns:app="http://schemas.android.com/apk/res-auto"
|
316
|
+
|
317
|
+
xmlns:tools="http://schemas.android.com/tools"
|
318
|
+
|
319
|
+
android:layout_width="match_parent"
|
320
|
+
|
321
|
+
android:layout_height="match_parent"
|
322
|
+
|
323
|
+
tools:context=".MainActivity">
|
324
|
+
|
325
|
+
|
326
|
+
|
327
|
+
<android.support.design.widget.AppBarLayout
|
328
|
+
|
329
|
+
android:layout_width="match_parent"
|
330
|
+
|
331
|
+
android:layout_height="wrap_content"
|
332
|
+
|
333
|
+
android:theme="@style/AppTheme.AppBarOverlay">
|
334
|
+
|
335
|
+
|
336
|
+
|
337
|
+
<android.support.v7.widget.Toolbar
|
338
|
+
|
339
|
+
android:id="@+id/toolbar"
|
340
|
+
|
341
|
+
android:layout_width="match_parent"
|
342
|
+
|
343
|
+
android:layout_height="?attr/actionBarSize"
|
344
|
+
|
345
|
+
android:background="?attr/colorPrimary"
|
346
|
+
|
347
|
+
app:popupTheme="@style/AppTheme.PopupOverlay" />
|
348
|
+
|
349
|
+
|
350
|
+
|
351
|
+
</android.support.design.widget.AppBarLayout>
|
352
|
+
|
353
|
+
|
354
|
+
|
355
|
+
<include layout="@layout/content_main" />
|
356
|
+
|
357
|
+
|
358
|
+
|
359
|
+
<android.support.design.widget.FloatingActionButton
|
360
|
+
|
361
|
+
android:id="@+id/fab"
|
362
|
+
|
363
|
+
android:layout_width="wrap_content"
|
364
|
+
|
365
|
+
android:layout_height="wrap_content"
|
366
|
+
|
367
|
+
android:layout_gravity="bottom|end"
|
368
|
+
|
369
|
+
android:layout_margin="@dimen/fab_margin"
|
370
|
+
|
371
|
+
app:srcCompat="@android:drawable/ic_dialog_email" />
|
372
|
+
|
373
|
+
|
374
|
+
|
375
|
+
|
376
|
+
|
377
|
+
|
378
|
+
|
379
|
+
</android.support.design.widget.CoordinatorLayout>
|
380
|
+
|
381
|
+
```
|
382
|
+
|
383
|
+
|
384
|
+
|
385
|
+
```xml
|
386
|
+
|
387
|
+
<?xml version="1.0" encoding="utf-8"?>
|
388
|
+
|
389
|
+
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
390
|
+
|
391
|
+
xmlns:app="http://schemas.android.com/apk/res-auto"
|
392
|
+
|
393
|
+
xmlns:tools="http://schemas.android.com/tools"
|
394
|
+
|
395
|
+
android:layout_width="match_parent"
|
396
|
+
|
397
|
+
android:layout_height="match_parent"
|
398
|
+
|
399
|
+
app:layout_behavior="@string/appbar_scrolling_view_behavior"
|
400
|
+
|
401
|
+
tools:context=".MainActivity"
|
402
|
+
|
403
|
+
tools:showIn="@layout/activity_main">
|
404
|
+
|
405
|
+
|
406
|
+
|
407
|
+
|
408
|
+
|
409
|
+
<view
|
410
|
+
|
411
|
+
class="com.example.paintview.PaintView"
|
412
|
+
|
413
|
+
id="@+id/view"
|
414
|
+
|
415
|
+
android:layout_width="match_parent"
|
416
|
+
|
417
|
+
android:layout_height="match_parent"
|
418
|
+
|
419
|
+
tools:layout_editor_absoluteX="45dp"
|
420
|
+
|
421
|
+
tools:layout_editor_absoluteY="421dp" />
|
422
|
+
|
423
|
+
</android.support.constraint.ConstraintLayout>
|
424
|
+
|
425
|
+
```
|