teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

2

2021/02/19 11:17

投稿

MucchoSP
MucchoSP

スコア1

title CHANGED
@@ -1,1 +1,1 @@
1
- androidにて、HorizontalScrollViewのlayoutが上手くいかない
1
+ androidにて、HorizontalScrollViewのlayoutが上手くいかない
body CHANGED
File without changes

1

2021/02/19 11:17

投稿

MucchoSP
MucchoSP

スコア1

title CHANGED
File without changes
body CHANGED
@@ -1,23 +1,88 @@
1
- ここに質問の内容を詳しく書いてください。
2
- (例)PHP(CakePHP)で●●なシステム作っていす。
1
+ すみません、androidアプリ勉強している者です。
3
- ■■な機能を実装中に以下のエラーメッセージが発生しました。
4
2
 
5
- ### 発生しいる問題・エラメッセージ
3
+ <HorizontalScrollView>を使っ横スクロルするボタンを作ろうと思っています。
6
4
 
7
- ```
5
+ ボタンを、縦にmatch_palentのようにしていっぱいに並べたかったのですが、挙動がwrap_contentみたいになって下に空白が出来てしまいます。
8
- エラーメッセージ
6
+ ググったら、
9
- ```
10
7
 
11
- ### 該当のソースコード
8
+ android:fillViewport="true"
12
9
 
13
- ```ここに言語名入力
10
+ つけると上手くいくみたいなのが書いてあったのですが、上手くいきません...
11
+
14
- ソースコード
12
+ こちらがコードです。
13
+ ```xml
14
+ <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
15
+ android:layout_width="fill_parent"
16
+ android:layout_height="fill_parent"
17
+ android:orientation="vertical">
18
+
19
+ <LinearLayout
20
+ android:layout_width="match_parent"
21
+ android:layout_height="wrap_content"
22
+ android:gravity="center">
23
+ <TextView
24
+ android:text="@string/select_title"
25
+ android:textSize="20dp"
26
+ android:layout_width="wrap_content"
27
+ android:layout_height="wrap_content"/>
28
+ </LinearLayout>
29
+
30
+ <HorizontalScrollView
31
+ android:id="@+id/selectButtons"
32
+ android:layout_width="match_parent"
33
+ android:layout_height="match_parent"
34
+ android:layout_weight="1"
35
+ android:fillViewport="true">
36
+ <LinearLayout
37
+ android:id="@+id/selectButtonLayout"
38
+ android:layout_width="wrap_content"
39
+ android:layout_height="match_parent"
40
+ android:orientation="horizontal">
41
+ </LinearLayout>
42
+ </HorizontalScrollView>
43
+
44
+ <LinearLayout
45
+ android:layout_width="match_parent"
46
+ android:layout_height="wrap_content"
47
+ android:orientation="horizontal">
48
+ <Button
49
+ android:id="@+id/backButton"
50
+ android:text="@string/back"
51
+ android:layout_width="match_parent"
52
+ android:layout_height="wrap_content"
53
+ android:layout_weight="1"/>
54
+ <Button
55
+ android:id="@+id/description"
56
+ android:text="@string/description"
57
+ android:layout_width="match_parent"
58
+ android:layout_height="wrap_content"
59
+ android:layout_weight="1"/>
60
+ </LinearLayout>
61
+
62
+ </LinearLayout>
15
63
  ```
16
64
 
17
- ### 試たこと
65
+ ボタンは、javaから直接配置ております。
18
66
 
67
+ ```java
68
+ LinearLayout selectScreen = (LinearLayout) findViewById(R.id.selectButtonLayout);
19
- ここに問題に対して試したことを記載してください。
69
+ for(int i=0;i<5;i++){
70
+ LinearLayout columnButtons = new LinearLayout(this);
71
+ columnButtons.setOrientation(LinearLayout.VERTICAL);
72
+ for(int j=0;j<4;j++){
73
+ Button button = new Button(this);
74
+ button.setText("stage"+(j+i*4+1));
75
+ button.setLayoutParams(new LinearLayout.LayoutParams(
76
+ LinearLayout.LayoutParams.MATCH_PARENT,
77
+ LinearLayout.LayoutParams.MATCH_PARENT));
78
+ button.setBackgroundColor(Color.rgb(169,206,236));
79
+ MarginLayoutParams lp = (MarginLayoutParams) button.getLayoutParams();
80
+ lp.setMargins(10,10,10,10);
81
+ button.setLayoutParams(lp);
82
+ columnButtons.addView(button);
83
+ }
84
+ selectScreen.addView(columnButtons);
85
+ }
86
+ ```
20
87
 
21
- ### 補足情報(FW/ツールのバージョンなど)
22
-
23
- ここにより詳細な情報記載してください。
88
+ 何か、うした方がいいという知っいる方がいれば教えてください。