質問編集履歴

6

ご助言による結果を追加。

2018/08/17 17:39

投稿

sunmo
sunmo

スコア10

test CHANGED
File without changes
test CHANGED
@@ -403,3 +403,11 @@
403
403
  ご存知の方、ご教示ください。よろしくお願いいたします。
404
404
 
405
405
  ![イメージ説明](214da96d73c4572dc04cc1e2c264dbfd.png)
406
+
407
+
408
+
409
+ 2018/08/18 02:37追記
410
+
411
+ ナビゲーションバーに割り込むも半分まで・・・ステータスバーより上にずれて描画されました。
412
+
413
+ ![イメージ説明](20252e24fc207f01eaf2fc031bfc79b3.png)

5

画像追加

2018/08/17 17:38

投稿

sunmo
sunmo

スコア10

test CHANGED
File without changes
test CHANGED
@@ -401,3 +401,5 @@
401
401
  特定の箇所にマークを付けたいので、四角い枠を画面いっぱいに表現したいのですが、できないものでしょうか?
402
402
 
403
403
  ご存知の方、ご教示ください。よろしくお願いいたします。
404
+
405
+ ![イメージ説明](214da96d73c4572dc04cc1e2c264dbfd.png)

4

画像追加できなかったので、表現削除

2018/08/10 18:01

投稿

sunmo
sunmo

スコア10

test CHANGED
File without changes
test CHANGED
@@ -392,7 +392,7 @@
392
392
 
393
393
  Viewのサイズを画面サイズ(getRealSize):1080×1920と同じにすると、
394
394
 
395
- 添付ファイルのようにステータスバーの下から矩形が描かれ、下側が表示できませんでした。
395
+ ステータスバーの下から矩形が描かれ、下側が表示できませんでした。
396
396
 
397
397
  フルスクリーンにゲームなどを起動すると、ステータスバーが消えるため、矩形も上に詰まる形で
398
398
 

3

試したことを追記

2018/08/10 17:49

投稿

sunmo
sunmo

スコア10

test CHANGED
File without changes
test CHANGED
@@ -385,3 +385,19 @@
385
385
  ただ、ナビゲーションバーとステータスバーのエリアは使用できませんでした。
386
386
 
387
387
  こちらを使用することはできるのでしょうか?
388
+
389
+
390
+
391
+ 2018/08/11 02:36追記
392
+
393
+ Viewのサイズを画面サイズ(getRealSize):1080×1920と同じにすると、
394
+
395
+ 添付ファイルのようにステータスバーの下から矩形が描かれ、下側が表示できませんでした。
396
+
397
+ フルスクリーンにゲームなどを起動すると、ステータスバーが消えるため、矩形も上に詰まる形で
398
+
399
+ 移動するのですが、下側の枠が描かれることはなく、矩形がそのまま上に移動するだけでした。
400
+
401
+ 特定の箇所にマークを付けたいので、四角い枠を画面いっぱいに表現したいのですが、できないものでしょうか?
402
+
403
+ ご存知の方、ご教示ください。よろしくお願いいたします。

2

一部ソース、レイアウトXMLを追加

2018/08/10 17:46

投稿

sunmo
sunmo

スコア10

test CHANGED
File without changes
test CHANGED
@@ -27,3 +27,361 @@
27
27
  上記について、canvasサイズをbitmapサイズまたは画面サイズにすることはできますでしょうか?
28
28
 
29
29
  どなたかご教示お願いいたします。
30
+
31
+
32
+
33
+ ### 該当のソースコード
34
+
35
+
36
+
37
+ ```java
38
+
39
+ package com.example.sumsu.overlaytest2;
40
+
41
+
42
+
43
+ import android.content.Context;
44
+
45
+ import android.graphics.Canvas;
46
+
47
+ import android.graphics.Color;
48
+
49
+ import android.graphics.Paint;
50
+
51
+ import android.graphics.Rect;
52
+
53
+ import android.util.AttributeSet;
54
+
55
+ import android.util.DisplayMetrics;
56
+
57
+ import android.view.View;
58
+
59
+ import android.view.WindowManager;
60
+
61
+
62
+
63
+ public class AnalyzeResultView extends View {
64
+
65
+
66
+
67
+ private Rect rect = null;
68
+
69
+ private Paint mPaint = new Paint();
70
+
71
+ private int displayWidth ;
72
+
73
+ private int displayHeight ;
74
+
75
+
76
+
77
+ public AnalyzeResultView(Context context) {
78
+
79
+ super(context);
80
+
81
+ }
82
+
83
+
84
+
85
+ public AnalyzeResultView(Context context,AttributeSet attrs) {
86
+
87
+ super(context,attrs);
88
+
89
+ }
90
+
91
+
92
+
93
+ public AnalyzeResultView(Context context, AttributeSet attrs, int defStyle){
94
+
95
+ super(context, attrs, defStyle);
96
+
97
+ }
98
+
99
+
100
+
101
+ // 結果をセットし描画を更新するためのメソッド
102
+
103
+ public void setAnalyzeResult(Rect rect) {
104
+
105
+ this.rect = rect;
106
+
107
+
108
+
109
+ postInvalidate();
110
+
111
+ }
112
+
113
+
114
+
115
+ /*@Override
116
+
117
+ protected void onLayout(boolean changed, int l, int t, int r, int b) {
118
+
119
+
120
+
121
+ invalidate();
122
+
123
+ }*/
124
+
125
+
126
+
127
+ @Override
128
+
129
+ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
130
+
131
+ super.onMeasure(widthMeasureSpec, heightMeasureSpec);
132
+
133
+
134
+
135
+ // 画面の縦横サイズとdpを取得
136
+
137
+ WindowManager wm = (WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE);
138
+
139
+ DisplayMetrics displayMetrics = new DisplayMetrics();
140
+
141
+ if(wm != null) {
142
+
143
+ wm.getDefaultDisplay().getMetrics(displayMetrics);
144
+
145
+ }
146
+
147
+ displayWidth = displayMetrics.widthPixels;
148
+
149
+ displayHeight = displayMetrics.heightPixels;
150
+
151
+
152
+
153
+ setMeasuredDimension(displayWidth,displayHeight);
154
+
155
+
156
+
157
+ }
158
+
159
+
160
+
161
+
162
+
163
+ @Override
164
+
165
+ public void onDraw(Canvas canvas) {
166
+
167
+ super.onDraw(canvas);
168
+
169
+
170
+
171
+
172
+
173
+ if(rect != null) {
174
+
175
+
176
+
177
+ //描画のペイント定義
178
+
179
+ mPaint.setAntiAlias(true);
180
+
181
+ mPaint.setStrokeWidth(12);
182
+
183
+ mPaint.setStyle(Paint.Style.STROKE);
184
+
185
+ mPaint.setColor(Color.BLUE);
186
+
187
+
188
+
189
+ // 矩形の描画処理...
190
+
191
+ canvas.drawRect(rect, mPaint);
192
+
193
+ }
194
+
195
+ }
196
+
197
+
198
+
199
+ }
200
+
201
+
202
+
203
+ ```
204
+
205
+ ```xml
206
+
207
+ activity_main.xml
208
+
209
+
210
+
211
+ <?xml version="1.0" encoding="utf-8"?>
212
+
213
+ <android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
214
+
215
+ xmlns:app="http://schemas.android.com/apk/res-auto"
216
+
217
+ xmlns:tools="http://schemas.android.com/tools"
218
+
219
+ android:layout_width="match_parent"
220
+
221
+ android:layout_height="match_parent"
222
+
223
+ tools:context=".MainActivity">
224
+
225
+
226
+
227
+ <Button
228
+
229
+ android:id="@+id/button"
230
+
231
+ android:layout_width="wrap_content"
232
+
233
+ android:layout_height="wrap_content"
234
+
235
+ android:layout_marginStart="8dp"
236
+
237
+ android:layout_marginTop="8dp"
238
+
239
+ android:onClick="button1_click"
240
+
241
+ android:text="@string/btnStart"
242
+
243
+ app:layout_constraintStart_toStartOf="parent"
244
+
245
+ app:layout_constraintTop_toTopOf="parent" />
246
+
247
+
248
+
249
+ <Button
250
+
251
+ android:id="@+id/button2"
252
+
253
+ android:layout_width="wrap_content"
254
+
255
+ android:layout_height="wrap_content"
256
+
257
+ android:layout_marginStart="8dp"
258
+
259
+ android:layout_marginTop="8dp"
260
+
261
+ android:onClick="button2_click"
262
+
263
+ android:text="@string/btnEnd"
264
+
265
+ app:layout_constraintStart_toStartOf="parent"
266
+
267
+ app:layout_constraintTop_toBottomOf="@+id/button" />
268
+
269
+ </android.support.constraint.ConstraintLayout>
270
+
271
+ ```
272
+
273
+ ```xml
274
+
275
+ overlay.xml
276
+
277
+
278
+
279
+ <?xml version="1.0" encoding="utf-8"?>
280
+
281
+ <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
282
+
283
+ xmlns:app="http://schemas.android.com/apk/res-auto"
284
+
285
+ android:layout_width="match_parent"
286
+
287
+ android:layout_height="match_parent">
288
+
289
+
290
+
291
+ <com.example.sumsu.overlaytest2.AnalyzeResultView
292
+
293
+ android:id="@+id/ResultView"
294
+
295
+ android:layout_width="match_parent"
296
+
297
+ android:layout_height="match_parent" />
298
+
299
+ </LinearLayout>
300
+
301
+ ```
302
+
303
+ ```xml
304
+
305
+ overlay2.xml
306
+
307
+
308
+
309
+ <?xml version="1.0" encoding="utf-8"?>
310
+
311
+ <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
312
+
313
+ android:id="@+id/linearLayout"
314
+
315
+ android:layout_width="wrap_content"
316
+
317
+ android:layout_height="wrap_content"
318
+
319
+ android:gravity="top|left"
320
+
321
+ android:orientation="vertical">
322
+
323
+
324
+
325
+ <LinearLayout
326
+
327
+ android:id="@+id/linearLayout1"
328
+
329
+ android:layout_width="wrap_content"
330
+
331
+ android:layout_height="wrap_content"
332
+
333
+ android:orientation="horizontal">
334
+
335
+
336
+
337
+ <Button
338
+
339
+ android:id="@+id/start"
340
+
341
+ android:layout_width="match_parent"
342
+
343
+ android:layout_height="wrap_content"
344
+
345
+ android:layout_weight="1"
346
+
347
+ android:background="#99FF0000"
348
+
349
+ android:text="Start" />
350
+
351
+
352
+
353
+ <Button
354
+
355
+ android:id="@+id/stop"
356
+
357
+ android:layout_width="match_parent"
358
+
359
+ android:layout_height="wrap_content"
360
+
361
+ android:layout_weight="1"
362
+
363
+ android:background="#9900ff00"
364
+
365
+ android:text="Stop" />
366
+
367
+
368
+
369
+ </LinearLayout>
370
+
371
+
372
+
373
+ </LinearLayout>
374
+
375
+ ```
376
+
377
+
378
+
379
+ ### 試したこと
380
+
381
+ 2018/08/08 18:07追記
382
+
383
+ onMeasureを追加することで、Viewのサイズの変更ができました。
384
+
385
+ ただ、ナビゲーションバーとステータスバーのエリアは使用できませんでした。
386
+
387
+ こちらを使用することはできるのでしょうか?

1

誤字修正

2018/08/08 09:08

投稿

sunmo
sunmo

スコア10

test CHANGED
File without changes
test CHANGED
@@ -1,4 +1,4 @@
1
- Service上に配置したボタンをタップすると、画面のキャプチャをとり、特定の箇所に
1
+ AndroidのアプリでService上に配置したボタンをタップすると、画面のキャプチャをとり、特定の箇所に
2
2
 
3
3
  DrawRectで矩形を付けたいのですが、スクリーン上のすべての領域を使用できず、
4
4