質問編集履歴

2

ソース用コードに修正

2016/09/27 02:24

投稿

DAEichan
DAEichan

スコア29

test CHANGED
File without changes
test CHANGED
@@ -8,8 +8,14 @@
8
8
 
9
9
  (Java勉強のためJavaの方でタイルを並べたい)
10
10
 
11
+
12
+
11
13
  ###該当のソースコード
12
14
 
15
+ ```package com.a2048example.a2048;
16
+
17
+
18
+
13
19
 
14
20
 
15
21
  import android.support.v7.app.AppCompatActivity;
@@ -148,7 +154,7 @@
148
154
 
149
155
  canvas.drawRect(160, 300, 100, 400, paint);
150
156
 
151
- canvas.drawText("2", 50, 50, paint);
157
+ canvas.drawText("2", 50, 60, paint);
152
158
 
153
159
 
154
160
 
@@ -216,7 +222,7 @@
216
222
 
217
223
 
218
224
 
219
- // 縦線(縦)
225
+ // 縦線(縦ドセン)
220
226
 
221
227
  paint.setStrokeWidth(StrokeWidth1);
222
228
 
@@ -401,3 +407,7 @@
401
407
 
402
408
 
403
409
  }
410
+
411
+
412
+
413
+ ```

1

ソースの追加と

2016/09/27 02:24

投稿

DAEichan
DAEichan

スコア29

test CHANGED
File without changes
test CHANGED
@@ -6,8 +6,398 @@
6
6
 
7
7
  GridLayoutでテキストを並べてみたけどなんか微調整がうまくいかず。。。
8
8
 
9
-
9
+ (Java勉強のためJavaの方でタイルを並べたい)
10
+
10
-
11
+ ###該当のソースコード
12
+
13
+
14
+
15
+ import android.support.v7.app.AppCompatActivity;
16
+
17
+ import android.os.Bundle;
18
+
19
+ import android.view.View;
20
+
11
- ###補足情報(言語/FW/ツール等のバージョンなど)
21
+ import android.view.GestureDetector;
22
+
12
-
23
+ import android.view.MotionEvent;
24
+
25
+ import android.graphics.Canvas;
26
+
27
+ import android.graphics.Color;
28
+
29
+ import android.content.Context;
30
+
13
- AndroidStudio,Java
31
+ import android.util.Log;
32
+
33
+ import android.widget.TextView;
34
+
35
+ import android.graphics.Paint;
36
+
37
+ import java.util.Random;
38
+
39
+
40
+
41
+
42
+
43
+ public class NaitiveActivity extends AppCompatActivity implements GestureDetector.OnGestureListener {
44
+
45
+
46
+
47
+ GestureDetector gestureDetector;
48
+
49
+ TextView tv;
50
+
51
+ private final int THRESHOLD = 40;
52
+
53
+
54
+
55
+
56
+
57
+ private static final int StrokeWidth1 = 20;
58
+
59
+ private static final int StrokeWidth2 = 30;
60
+
61
+ //Canvas中心点
62
+
63
+ private float xc = 0.0f;
64
+
65
+ private float yc = 0.0f;
66
+
67
+
68
+
69
+ @Override
70
+
71
+ protected void onCreate(Bundle savedInstanceState) {
72
+
73
+ super.onCreate(savedInstanceState);
74
+
75
+ setContentView(R.layout.activity_naitive);
76
+
77
+ //インスタンスの生成
78
+
79
+ DrawView view = new DrawView(this);
80
+
81
+ setContentView(view);
82
+
83
+ gestureDetector = new GestureDetector(this, this);
84
+
85
+
86
+
87
+ }
88
+
89
+
90
+
91
+ class DrawView extends View {
92
+
93
+ Paint paint;
94
+
95
+ Random randInit1 = new Random();
96
+
97
+ //Random randInit2 = new Random();
98
+
99
+ public DrawView(Context context){
100
+
101
+ super(context);
102
+
103
+ paint = new Paint();
104
+
105
+ }
106
+
107
+
108
+
109
+ @Override
110
+
111
+ protected void onDraw(Canvas canvas){
112
+
113
+
114
+
115
+ // Canvas 中心点
116
+
117
+ //xc = canvas.getWidth()/2;
118
+
119
+ //yc = canvas.getHeight()/2;
120
+
121
+ //初期2パネル生成用ランダム変数(まだ同じ数字が出る)
122
+
123
+ for(int i = 0;i < 1; i++) {
124
+
125
+ int initRand1 = randInit1.nextInt(15);
126
+
127
+ Log.d("randInit1", "RANDOM:" + initRand1);
128
+
129
+ switch(2) {
130
+
131
+ case 1:
132
+
133
+ // 数字パネル
134
+
135
+ paint.setColor(Color.RED);
136
+
137
+ canvas.drawText("書きたい文字", 500, 400, paint);
138
+
139
+
140
+
141
+ case 2:
142
+
143
+ // 数字パネル
144
+
145
+ paint.setColor(Color.RED);
146
+
147
+ paint.setAntiAlias(true);
148
+
149
+ canvas.drawRect(160, 300, 100, 400, paint);
150
+
151
+ canvas.drawText("2", 50, 50, paint);
152
+
153
+
154
+
155
+ case 3:
156
+
157
+ // 数字パネル
158
+
159
+ paint.setColor(Color.RED);
160
+
161
+ paint.setAntiAlias(true);
162
+
163
+ canvas.drawRect(240, 300, 100, 400, paint);
164
+
165
+
166
+
167
+ }
168
+
169
+ }
170
+
171
+
172
+
173
+
174
+
175
+ // 数字パネル
176
+
177
+ paint.setColor(Color.RED);
178
+
179
+ paint.setStyle(Paint.Style.STROKE);
180
+
181
+ paint.setStrokeWidth(StrokeWidth2);
182
+
183
+ paint.setAntiAlias(true);
184
+
185
+ canvas.drawRect(80, 300, 1000, 1280, paint);
186
+
187
+
188
+
189
+ // 内側塗り
190
+
191
+ paint.setColor(Color.argb(255, 192, 192, 192));
192
+
193
+ paint.setStyle(Paint.Style.FILL_AND_STROKE);
194
+
195
+ paint.setStrokeWidth(StrokeWidth2);
196
+
197
+ paint.setAntiAlias(true);
198
+
199
+ // (x1,y1,x2,y2,paint) 左上の座標(x1,y1), 右下の座標(x2,y2)
200
+
201
+ canvas.drawRect(80, 300, 1000, 1280, paint);
202
+
203
+
204
+
205
+ // 枠
206
+
207
+ paint.setColor(Color.GRAY);
208
+
209
+ paint.setStyle(Paint.Style.STROKE);
210
+
211
+ paint.setStrokeWidth(StrokeWidth2);
212
+
213
+ paint.setAntiAlias(true);
214
+
215
+ canvas.drawRect(80, 300, 1000, 1280, paint);
216
+
217
+
218
+
219
+ // 縦線(縦)
220
+
221
+ paint.setStrokeWidth(StrokeWidth1);
222
+
223
+ paint.setColor(Color.GRAY);
224
+
225
+ // (x1,y1,x2,y2,paint) 始点の座標(x1,y1), 終点の座標(x2,y2)
226
+
227
+ canvas.drawLine(545, 300, 545, 1280, paint);
228
+
229
+
230
+
231
+ // 縦線(右)
232
+
233
+ paint.setStrokeWidth(StrokeWidth1);
234
+
235
+ paint.setColor(Color.GRAY);
236
+
237
+ // (x1,y1,x2,y2,paint) 始点の座標(x1,y1), 終点の座標(x2,y2)
238
+
239
+ canvas.drawLine(780, 300, 780, 1280, paint);
240
+
241
+
242
+
243
+ // 縦線(左)
244
+
245
+ paint.setStrokeWidth(StrokeWidth1);
246
+
247
+ paint.setColor(Color.GRAY);
248
+
249
+ // (x1,y1,x2,y2,paint) 始点の座標(x1,y1), 終点の座標(x2,y2)
250
+
251
+ canvas.drawLine(320, 300, 320, 1280, paint);
252
+
253
+
254
+
255
+ // 線(横真ん中)
256
+
257
+ paint.setStrokeWidth(StrokeWidth1);
258
+
259
+ paint.setColor(Color.GRAY);
260
+
261
+ // (x1,y1,x2,y2,paint) 始点の座標(x1,y1), 終点の座標(x2,y2)
262
+
263
+ canvas.drawLine(80, 800, 1000, 800, paint);
264
+
265
+
266
+
267
+ // 線(横上部)
268
+
269
+ paint.setStrokeWidth(StrokeWidth1);
270
+
271
+ paint.setColor(Color.GRAY);
272
+
273
+ // (x1,y1,x2,y2,paint) 始点の座標(x1,y1), 終点の座標(x2,y2)
274
+
275
+ canvas.drawLine(80, 551, 1000, 551, paint);
276
+
277
+
278
+
279
+ // 線(横下部)
280
+
281
+ paint.setStrokeWidth(StrokeWidth1);
282
+
283
+ paint.setColor(Color.GRAY);
284
+
285
+ // (x1,y1,x2,y2,paint) 始点の座標(x1,y1), 終点の座標(x2,y2)
286
+
287
+ canvas.drawLine(80, 1035, 1000, 1035, paint);
288
+
289
+
290
+
291
+ }
292
+
293
+ }
294
+
295
+ public boolean onTouchEvent(MotionEvent event) {
296
+
297
+ gestureDetector.onTouchEvent(event);
298
+
299
+ return true;
300
+
301
+ }
302
+
303
+
304
+
305
+ @Override
306
+
307
+ public boolean onDown(MotionEvent e) {
308
+
309
+ // TODO 自動生成されたメソッド・スタブ
310
+
311
+ return false;
312
+
313
+ }
314
+
315
+
316
+
317
+ @Override
318
+
319
+ public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
320
+
321
+ Log.d("onFling", "start");
322
+
323
+
324
+
325
+ if (e2.getX() - e1.getX() > THRESHOLD) {
326
+
327
+ Log.d("onFling", "右");
328
+
329
+ } else if (e2.getX() - e1.getX() < -THRESHOLD) {
330
+
331
+ Log.d("onFling", "左");
332
+
333
+ } else if (e2.getY() - e1.getY() > THRESHOLD) {
334
+
335
+ Log.d("onFling", "下");
336
+
337
+ } else if (e2.getY() - e1.getY() < -THRESHOLD) {
338
+
339
+ Log.d("onFling", "上");
340
+
341
+ }
342
+
343
+
344
+
345
+ return false;
346
+
347
+ }
348
+
349
+
350
+
351
+
352
+
353
+ @Override
354
+
355
+ public void onLongPress(MotionEvent e) {
356
+
357
+ // TODO 自動生成されたメソッド・スタブ
358
+
359
+
360
+
361
+ }
362
+
363
+
364
+
365
+ @Override
366
+
367
+ public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
368
+
369
+ // TODO 自動生成されたメソッド・スタブ
370
+
371
+ return false;
372
+
373
+ }
374
+
375
+
376
+
377
+
378
+
379
+ @Override
380
+
381
+ public void onShowPress(MotionEvent e) {
382
+
383
+ // TODO 自動生成されたメソッド・スタブ
384
+
385
+
386
+
387
+ }
388
+
389
+
390
+
391
+ @Override
392
+
393
+ public boolean onSingleTapUp(MotionEvent e) {
394
+
395
+ // TODO 自動生成されたメソッド・スタブ
396
+
397
+ return false;
398
+
399
+ }
400
+
401
+
402
+
403
+ }