質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
Android

Androidは、Google社が開発したスマートフォンやタブレットなど携帯端末向けのプラットフォームです。 カーネル・ミドルウェア・ユーザーインターフェイス・ウェブブラウザ・電話帳などのアプリケーションやソフトウェアをひとつにまとめて構成。 カーネル・ライブラリ・ランタイムはほとんどがC言語/C++、アプリケーションなどはJavaSEのサブセットとAndroid環境で書かれています。

Q&A

解決済

1回答

1672閲覧

androidにて、HorizontalScrollView内のlayoutが上手くいかない

MucchoSP

総合スコア1

Android

Androidは、Google社が開発したスマートフォンやタブレットなど携帯端末向けのプラットフォームです。 カーネル・ミドルウェア・ユーザーインターフェイス・ウェブブラウザ・電話帳などのアプリケーションやソフトウェアをひとつにまとめて構成。 カーネル・ライブラリ・ランタイムはほとんどがC言語/C++、アプリケーションなどはJavaSEのサブセットとAndroid環境で書かれています。

0グッド

0クリップ

投稿2021/02/19 10:59

編集2021/02/19 11:17

すみません、androidアプリを勉強している者です。

<HorizontalScrollView>を使って横スクロールするボタンを作ろうと思っています。

ボタンを、縦にmatch_palentのようにしていっぱいに並べたかったのですが、挙動がwrap_contentみたいになって下に空白が出来てしまいます。
ググったら、

android:fillViewport="true"

をつけると上手くいくみたいなのが書いてあったのですが、上手くいきません...

こちらがコードです。

xml

1<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 2 android:layout_width="fill_parent" 3 android:layout_height="fill_parent" 4 android:orientation="vertical"> 5 6 <LinearLayout 7 android:layout_width="match_parent" 8 android:layout_height="wrap_content" 9 android:gravity="center"> 10 <TextView 11 android:text="@string/select_title" 12 android:textSize="20dp" 13 android:layout_width="wrap_content" 14 android:layout_height="wrap_content"/> 15 </LinearLayout> 16 17 <HorizontalScrollView 18 android:id="@+id/selectButtons" 19 android:layout_width="match_parent" 20 android:layout_height="match_parent" 21 android:layout_weight="1" 22 android:fillViewport="true"> 23 <LinearLayout 24 android:id="@+id/selectButtonLayout" 25 android:layout_width="wrap_content" 26 android:layout_height="match_parent" 27 android:orientation="horizontal"> 28 </LinearLayout> 29 </HorizontalScrollView> 30 31 <LinearLayout 32 android:layout_width="match_parent" 33 android:layout_height="wrap_content" 34 android:orientation="horizontal"> 35 <Button 36 android:id="@+id/backButton" 37 android:text="@string/back" 38 android:layout_width="match_parent" 39 android:layout_height="wrap_content" 40 android:layout_weight="1"/> 41 <Button 42 android:id="@+id/description" 43 android:text="@string/description" 44 android:layout_width="match_parent" 45 android:layout_height="wrap_content" 46 android:layout_weight="1"/> 47 </LinearLayout> 48 49</LinearLayout>

ボタンは、javaから直接配置しております。

java

1LinearLayout selectScreen = (LinearLayout) findViewById(R.id.selectButtonLayout); 2 for(int i=0;i<5;i++){ 3 LinearLayout columnButtons = new LinearLayout(this); 4 columnButtons.setOrientation(LinearLayout.VERTICAL); 5 for(int j=0;j<4;j++){ 6 Button button = new Button(this); 7 button.setText("stage"+(j+i*4+1)); 8 button.setLayoutParams(new LinearLayout.LayoutParams( 9 LinearLayout.LayoutParams.MATCH_PARENT, 10 LinearLayout.LayoutParams.MATCH_PARENT)); 11 button.setBackgroundColor(Color.rgb(169,206,236)); 12 MarginLayoutParams lp = (MarginLayoutParams) button.getLayoutParams(); 13 lp.setMargins(10,10,10,10); 14 button.setLayoutParams(lp); 15 columnButtons.addView(button); 16 } 17 selectScreen.addView(columnButtons); 18 }

何か、こうした方がいいということを知っている方がいれば教えてください。

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

自己解決

Javaでボタンを配置するときに、縦に積むために、一度LinearLayoutにいれるのですが、そこのLinearLayoutの高さを設定していなかったのが原因でした。
あと、ボタンのweightを設定してあげないと崩れます。

投稿2021/02/20 00:37

MucchoSP

総合スコア1

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問