質問編集履歴
5
情報変更
test
CHANGED
File without changes
|
test
CHANGED
@@ -44,10 +44,6 @@
|
|
44
44
|
|
45
45
|
|
46
46
|
|
47
|
-
import jp.techacademy.shoichi.ito.aft.R;
|
48
|
-
|
49
|
-
|
50
|
-
|
51
47
|
public class MainActivity extends AppCompatActivity {
|
52
48
|
|
53
49
|
|
4
写真追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -461,3 +461,11 @@
|
|
461
461
|
どこをどう変更して追加すると
|
462
462
|
|
463
463
|
エラーがなく正常に作動するのか、わかりませんmm
|
464
|
+
|
465
|
+
|
466
|
+
|
467
|
+
エラーメッセージ
|
468
|
+
|
469
|
+
↓
|
470
|
+
|
471
|
+
![イメージ説明](71227295b2c7e2647408b56f272dca91.png)
|
3
例の追記
test
CHANGED
File without changes
|
test
CHANGED
@@ -1,16 +1,20 @@
|
|
1
|
+
少し長くなります。また文章が
|
2
|
+
|
3
|
+
わからない箇所もあるかと思いますが
|
4
|
+
|
5
|
+
どうぞよろしくお願いいたします。
|
6
|
+
|
7
|
+
|
8
|
+
|
1
|
-
android studioでショッピングサイトの作成をしております。
|
9
|
+
現在、android studioでショッピングサイトの作成をしております。
|
10
|
+
|
2
|
-
|
11
|
+
BottomNavigationViewにて作成しているのですが
|
3
|
-
|
4
|
-
|
12
|
+
|
5
|
-
アイコンの大きさを均等にする方法を教えていただきたいです。
|
13
|
+
下に表示されるアイコンの大きさを均等にする方法を教えていただきたいです。
|
6
|
-
|
7
|
-
|
8
|
-
|
14
|
+
|
15
|
+
|
16
|
+
|
9
|
-
|
17
|
+
写真のように[商品]だけが大きく表示されてしまいます。
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
18
|
|
15
19
|
|
16
20
|
|
@@ -18,9 +22,11 @@
|
|
18
22
|
|
19
23
|
|
20
24
|
|
21
|
-
|
25
|
+
当方が書いてきたコードは以下です。
|
26
|
+
|
22
|
-
|
27
|
+
MaimActivity.java
|
28
|
+
|
23
|
-
|
29
|
+
↓↓↓↓↓↓↓↓↓↓↓↓↓
|
24
30
|
|
25
31
|
|
26
32
|
|
@@ -122,17 +128,19 @@
|
|
122
128
|
|
123
129
|
}
|
124
130
|
|
125
|
-
コード
|
126
|
-
|
127
|
-
```
|
131
|
+
```
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
132
|
+
|
133
|
+
|
134
|
+
|
135
|
+
|
136
|
+
|
137
|
+
|
138
|
+
|
139
|
+
|
140
|
+
|
133
|
-
|
141
|
+
Activity Main
|
142
|
+
|
134
|
-
|
143
|
+
↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓
|
135
|
-
|
136
144
|
|
137
145
|
```<?xml version="1.0" encoding="utf-8"?>
|
138
146
|
|
@@ -172,11 +180,17 @@
|
|
172
180
|
|
173
181
|
</android.support.constraint.ConstraintLayout>
|
174
182
|
|
175
|
-
|
183
|
+
|
176
|
-
|
184
|
+
|
177
|
-
```
|
185
|
+
```
|
186
|
+
|
187
|
+
|
188
|
+
|
189
|
+
|
190
|
+
|
191
|
+
|
192
|
+
|
178
|
-
|
193
|
+
navigation.xml
|
179
|
-
|
180
194
|
|
181
195
|
|
182
196
|
|
@@ -242,6 +256,208 @@
|
|
242
256
|
|
243
257
|
|
244
258
|
|
245
|
-
コード
|
246
|
-
|
247
|
-
```
|
259
|
+
```
|
260
|
+
|
261
|
+
手順①
|
262
|
+
|
263
|
+
[4つ以上のアイテムを均等の大きさで並べる]
|
264
|
+
|
265
|
+
4つ以上のアイテムを均等に並べるにはレイアウトをごにょごにょする必要があるが、今回はBottomNavigationViewを継承してBottomNavigationViewの独自クラスをするのではなく
|
266
|
+
|
267
|
+
「BottomNavigationViewHelper」というヘルパークラスを作成してBottomNavigationViewを作るときにレイアウトを調整する。
|
268
|
+
|
269
|
+
|
270
|
+
|
271
|
+
BottomNavigationViewHelperを新規に作成する
|
272
|
+
|
273
|
+
こちらがwebからみつけだしたコードなのですが
|
274
|
+
|
275
|
+
どう変更したら良いか教え頂けますと幸いです。
|
276
|
+
|
277
|
+
|
278
|
+
|
279
|
+
|
280
|
+
|
281
|
+
|
282
|
+
|
283
|
+
```
|
284
|
+
|
285
|
+
package com.myapp.myapp;
|
286
|
+
|
287
|
+
|
288
|
+
|
289
|
+
import android.support.design.internal.BottomNavigationItemView;
|
290
|
+
|
291
|
+
import android.support.design.internal.BottomNavigationMenuView;
|
292
|
+
|
293
|
+
import android.support.design.widget.BottomNavigationView;
|
294
|
+
|
295
|
+
|
296
|
+
|
297
|
+
import java.lang.reflect.Field;
|
298
|
+
|
299
|
+
|
300
|
+
|
301
|
+
public class BottomNavigationViewHelper {
|
302
|
+
|
303
|
+
|
304
|
+
|
305
|
+
/**
|
306
|
+
|
307
|
+
* BottomNavigationViewのアイテムのサイズの調整、アイコンサイズ調整、タイトルの削除
|
308
|
+
|
309
|
+
*
|
310
|
+
|
311
|
+
* @param view
|
312
|
+
|
313
|
+
*/
|
314
|
+
|
315
|
+
public static void disableShiftMode(BottomNavigationView view) {
|
316
|
+
|
317
|
+
BottomNavigationMenuView menuView = (BottomNavigationMenuView) view.getChildAt(0);
|
318
|
+
|
319
|
+
try {
|
320
|
+
|
321
|
+
|
322
|
+
|
323
|
+
Field shiftingMode = menuView.getClass().getDeclaredField("mShiftingMode");
|
324
|
+
|
325
|
+
shiftingMode.setAccessible(true);
|
326
|
+
|
327
|
+
shiftingMode.setBoolean(menuView, false);
|
328
|
+
|
329
|
+
shiftingMode.setAccessible(false);
|
330
|
+
|
331
|
+
|
332
|
+
|
333
|
+
for (int i = 0; i < menuView.getChildCount(); i++) {
|
334
|
+
|
335
|
+
|
336
|
+
|
337
|
+
/**
|
338
|
+
|
339
|
+
* アイテムの幅調整
|
340
|
+
|
341
|
+
*/
|
342
|
+
|
343
|
+
BottomNavigationItemView bottomNavigationItemView = (BottomNavigationItemView) menuView.getChildAt(i);
|
344
|
+
|
345
|
+
// noinspection RestrictedApi
|
346
|
+
|
347
|
+
bottomNavigationItemView.setShiftingMode(false);
|
348
|
+
|
349
|
+
// チェックされた値を設定すると、ビューが更新されるみたい
|
350
|
+
|
351
|
+
// noinspection RestrictedApi
|
352
|
+
|
353
|
+
bottomNavigationItemView.setChecked(false);
|
354
|
+
|
355
|
+
|
356
|
+
|
357
|
+
}
|
358
|
+
|
359
|
+
|
360
|
+
|
361
|
+
} catch (NoSuchFieldException e) {
|
362
|
+
|
363
|
+
e.printStackTrace();
|
364
|
+
|
365
|
+
} catch (IllegalAccessException e) {
|
366
|
+
|
367
|
+
e.printStackTrace();
|
368
|
+
|
369
|
+
}
|
370
|
+
|
371
|
+
|
372
|
+
|
373
|
+
}
|
374
|
+
|
375
|
+
}
|
376
|
+
|
377
|
+
|
378
|
+
|
379
|
+
```
|
380
|
+
|
381
|
+
|
382
|
+
|
383
|
+
手順②
|
384
|
+
|
385
|
+
|
386
|
+
|
387
|
+
|
388
|
+
|
389
|
+
```
|
390
|
+
|
391
|
+
ActivityからBottomNavigationViewHelperを呼びす
|
392
|
+
|
393
|
+
onCreateでBottomNavigationViewHelper#disableShiftModeへBottomNavigationViewを渡し調整、その後ついでに選択のリスナーを実装
|
394
|
+
|
395
|
+
|
396
|
+
|
397
|
+
// ボトムナビゲーションを読み込む
|
398
|
+
|
399
|
+
BottomNavigationView bottomavigation = (BottomNavigationView) findViewById(R.id.bottom_navigation);
|
400
|
+
|
401
|
+
// BottomNavigationViewHelperでアイテムのサイズ、アニメーションを調整
|
402
|
+
|
403
|
+
BottomNavigationViewHelper.disableShiftMode(bottomavigation);
|
404
|
+
|
405
|
+
// BottomNavigationViewを選択したときのリスナー
|
406
|
+
|
407
|
+
bottomavigation.setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() {
|
408
|
+
|
409
|
+
@Override
|
410
|
+
|
411
|
+
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
|
412
|
+
|
413
|
+
|
414
|
+
|
415
|
+
// 各選択したときの処理
|
416
|
+
|
417
|
+
switch (item.getItemId()) {
|
418
|
+
|
419
|
+
case R.id.nav_camera:
|
420
|
+
|
421
|
+
|
422
|
+
|
423
|
+
return true;
|
424
|
+
|
425
|
+
case R.id.nav_gallery:
|
426
|
+
|
427
|
+
|
428
|
+
|
429
|
+
return true;
|
430
|
+
|
431
|
+
case R.id.nav_slideshow:
|
432
|
+
|
433
|
+
|
434
|
+
|
435
|
+
return true;
|
436
|
+
|
437
|
+
case R.id.nav_manage:
|
438
|
+
|
439
|
+
|
440
|
+
|
441
|
+
return true;
|
442
|
+
|
443
|
+
}
|
444
|
+
|
445
|
+
return false;
|
446
|
+
|
447
|
+
}
|
448
|
+
|
449
|
+
});
|
450
|
+
|
451
|
+
|
452
|
+
|
453
|
+
|
454
|
+
|
455
|
+
|
456
|
+
|
457
|
+
```
|
458
|
+
|
459
|
+
|
460
|
+
|
461
|
+
どこをどう変更して追加すると
|
462
|
+
|
463
|
+
エラーがなく正常に作動するのか、わかりませんmm
|
2
コード
test
CHANGED
@@ -1 +1 @@
|
|
1
|
-
全て「商品」と同じ表示にしたい
|
1
|
+
全て「商品」と同じ表示にしたい
|
test
CHANGED
@@ -15,3 +15,233 @@
|
|
15
15
|
|
16
16
|
|
17
17
|
![イメージ説明](a7d19741b01e7e2012b03106870708fb.png)
|
18
|
+
|
19
|
+
|
20
|
+
|
21
|
+
メインコードは以下です。
|
22
|
+
|
23
|
+
|
24
|
+
|
25
|
+
|
26
|
+
|
27
|
+
```import android.os.Bundle;
|
28
|
+
|
29
|
+
import android.support.annotation.NonNull;
|
30
|
+
|
31
|
+
import android.support.design.widget.BottomNavigationView;
|
32
|
+
|
33
|
+
import android.support.v7.app.AppCompatActivity;
|
34
|
+
|
35
|
+
import android.view.MenuItem;
|
36
|
+
|
37
|
+
import android.widget.TextView;
|
38
|
+
|
39
|
+
|
40
|
+
|
41
|
+
import jp.techacademy.shoichi.ito.aft.R;
|
42
|
+
|
43
|
+
|
44
|
+
|
45
|
+
public class MainActivity extends AppCompatActivity {
|
46
|
+
|
47
|
+
|
48
|
+
|
49
|
+
private TextView mTextMessage;
|
50
|
+
|
51
|
+
|
52
|
+
|
53
|
+
private BottomNavigationView.OnNavigationItemSelectedListener mOnNavigationItemSelectedListener
|
54
|
+
|
55
|
+
= new BottomNavigationView.OnNavigationItemSelectedListener() {
|
56
|
+
|
57
|
+
|
58
|
+
|
59
|
+
@Override
|
60
|
+
|
61
|
+
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
|
62
|
+
|
63
|
+
switch (item.getItemId()) {
|
64
|
+
|
65
|
+
case R.id.navigation_product:
|
66
|
+
|
67
|
+
mTextMessage.setText(R.string.title_product);
|
68
|
+
|
69
|
+
return true;
|
70
|
+
|
71
|
+
case R.id.navigation_cart:
|
72
|
+
|
73
|
+
mTextMessage.setText(R.string.title_cart);
|
74
|
+
|
75
|
+
return true;
|
76
|
+
|
77
|
+
case R.id.navigation_delivery_status:
|
78
|
+
|
79
|
+
mTextMessage.setText(R.string.title_delivery_status);
|
80
|
+
|
81
|
+
return true;
|
82
|
+
|
83
|
+
case R.id.navigation_mypage:
|
84
|
+
|
85
|
+
mTextMessage.setText(R.string.title_mypage);
|
86
|
+
|
87
|
+
return true;
|
88
|
+
|
89
|
+
case R.id.navigation_other:
|
90
|
+
|
91
|
+
mTextMessage.setText(R.string.title_other);
|
92
|
+
|
93
|
+
return true;
|
94
|
+
|
95
|
+
}
|
96
|
+
|
97
|
+
return false;
|
98
|
+
|
99
|
+
}
|
100
|
+
|
101
|
+
};
|
102
|
+
|
103
|
+
|
104
|
+
|
105
|
+
@Override
|
106
|
+
|
107
|
+
protected void onCreate(Bundle savedInstanceState) {
|
108
|
+
|
109
|
+
super.onCreate(savedInstanceState);
|
110
|
+
|
111
|
+
setContentView(R.layout.activity_main);
|
112
|
+
|
113
|
+
|
114
|
+
|
115
|
+
mTextMessage = (TextView) findViewById(R.id.message);
|
116
|
+
|
117
|
+
BottomNavigationView navigation = (BottomNavigationView) findViewById(R.id.navigation);
|
118
|
+
|
119
|
+
navigation.setOnNavigationItemSelectedListener(mOnNavigationItemSelectedListener);
|
120
|
+
|
121
|
+
}
|
122
|
+
|
123
|
+
}
|
124
|
+
|
125
|
+
コード
|
126
|
+
|
127
|
+
```
|
128
|
+
|
129
|
+
|
130
|
+
|
131
|
+
|
132
|
+
|
133
|
+
レイアウトは以下二つ
|
134
|
+
|
135
|
+
|
136
|
+
|
137
|
+
```<?xml version="1.0" encoding="utf-8"?>
|
138
|
+
|
139
|
+
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
140
|
+
|
141
|
+
xmlns:app="http://schemas.android.com/apk/res-auto"
|
142
|
+
|
143
|
+
xmlns:tools="http://schemas.android.com/tools"
|
144
|
+
|
145
|
+
android:id="@+id/container"
|
146
|
+
|
147
|
+
android:layout_width="match_parent"
|
148
|
+
|
149
|
+
android:layout_height="match_parent"
|
150
|
+
|
151
|
+
tools:context=".MainActivity">
|
152
|
+
|
153
|
+
|
154
|
+
|
155
|
+
<android.support.design.widget.BottomNavigationView
|
156
|
+
|
157
|
+
android:id="@+id/navigation"
|
158
|
+
|
159
|
+
android:layout_width="0dp"
|
160
|
+
|
161
|
+
android:layout_height="59dp"
|
162
|
+
|
163
|
+
android:background="?android:attr/windowBackground"
|
164
|
+
|
165
|
+
app:layout_constraintBottom_toBottomOf="parent"
|
166
|
+
|
167
|
+
app:layout_constraintRight_toRightOf="parent"
|
168
|
+
|
169
|
+
app:menu="@menu/navigation" />
|
170
|
+
|
171
|
+
|
172
|
+
|
173
|
+
</android.support.constraint.ConstraintLayout>
|
174
|
+
|
175
|
+
コード
|
176
|
+
|
177
|
+
```
|
178
|
+
|
179
|
+
|
180
|
+
|
181
|
+
|
182
|
+
|
183
|
+
```<?xml version="1.0" encoding="utf-8"?>
|
184
|
+
|
185
|
+
<menu xmlns:android="http://schemas.android.com/apk/res/android">
|
186
|
+
|
187
|
+
|
188
|
+
|
189
|
+
<item
|
190
|
+
|
191
|
+
android:id="@+id/navigation_product"
|
192
|
+
|
193
|
+
android:icon="@drawable/ic_home_black_24dp"
|
194
|
+
|
195
|
+
android:title="商品" />
|
196
|
+
|
197
|
+
|
198
|
+
|
199
|
+
<item
|
200
|
+
|
201
|
+
android:id="@+id/navigation_cart"
|
202
|
+
|
203
|
+
android:icon="@drawable/ic_shopping_cart_black_24dp"
|
204
|
+
|
205
|
+
android:title="カート" />
|
206
|
+
|
207
|
+
|
208
|
+
|
209
|
+
<item
|
210
|
+
|
211
|
+
android:id="@+id/navigation_delivery_status"
|
212
|
+
|
213
|
+
android:icon="@drawable/ic_local_shipping_black_24dp"
|
214
|
+
|
215
|
+
android:title="配送状況" />
|
216
|
+
|
217
|
+
|
218
|
+
|
219
|
+
<item
|
220
|
+
|
221
|
+
android:id="@+id/navigation_mypage"
|
222
|
+
|
223
|
+
android:icon="@drawable/ic_person_black_24dp"
|
224
|
+
|
225
|
+
android:title="マイページ" />
|
226
|
+
|
227
|
+
|
228
|
+
|
229
|
+
<item
|
230
|
+
|
231
|
+
android:id="@+id/navigation_other"
|
232
|
+
|
233
|
+
android:icon="@drawable/ic_settings_black_24dp"
|
234
|
+
|
235
|
+
android:title="その他" />
|
236
|
+
|
237
|
+
|
238
|
+
|
239
|
+
|
240
|
+
|
241
|
+
</menu>
|
242
|
+
|
243
|
+
|
244
|
+
|
245
|
+
コード
|
246
|
+
|
247
|
+
```
|
1
タイトル
test
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
全て「商品」と同じ表示にしたい...
|
test
CHANGED
File without changes
|