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

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

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

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

Q&A

解決済

2回答

4086閲覧

余白の埋め方について

buibui80

総合スコア1033

Android

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

0グッド

1クリップ

投稿2015/10/09 04:43

レイアウトについて質問がございます。
以下の画像の様にメニューバーを作成して配置する時、
画面サイズに合わせて余白を埋めたいのですがどの様にすれば良いでしょうか?
イメージ説明
以下のXMLではSpaceに固定値を設定している状態です。

xml

1 <LinearLayout 2 android:layout_width="fill_parent" 3 android:layout_height="wrap_content" 4 android:baselineAligned="false" 5 android:gravity="center" 6 android:orientation="horizontal" 7 android:background="#b2c6cb"> 8 9 <Button android:id="@+id/btn_id1" 10 android:layout_width="40dp" 11 android:layout_height="40dp" 12 android:scaleType="fitCenter" 13 android:layout_marginLeft="10dp" 14 android:layout_marginTop="15dp" 15 android:layout_marginBottom="15dp" /> 16 <Button android:id="@+id/btn_id2" 17 android:layout_width="40dp" 18 android:layout_height="40dp" 19 android:scaleType="fitCenter" 20 android:layout_marginLeft="10dp" 21 android:layout_marginTop="15dp" 22 android:layout_marginBottom="15dp" /> 23 24 <Space android:id="@+id/space_id" 25 android:layout_width="50dip" 26 android:layout_height="match_parent" 27 android:layout_marginLeft="10dp" /> 28 29 <Button android:id="@+id/btn_id3" 30 android:layout_width="40dp" 31 android:layout_height="40dp" 32 android:scaleType="fitCenter" 33 android:layout_marginLeft="10dp" 34 android:layout_marginTop="15dp" 35 android:layout_marginBottom="15dp" /> 36 <Button android:id="@+id/btn_id4" 37 android:layout_width="40dp" 38 android:layout_height="40dp" 39 android:scaleType="fitCenter" 40 android:layout_marginLeft="10dp" 41 android:layout_marginTop="15dp" 42 android:layout_marginBottom="15dp" /> 43 </LinearLayout>

よろしくお願い致します。

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

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

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

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

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

guest

回答2

0

LinearLayoutのgravityを外して,各Buttonにlayout_gravityを設定すればいいのではないでしょうか.
Spaceを入れずともButtonが左右に振られると思います.

投稿2015/10/09 04:47

swordone

総合スコア20651

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

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

buibui80

2015/10/09 05:01

以下の様にしたら左詰めになってしまいました。 記述方法が間違っているのでしょうか? <LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:baselineAligned="false" android:orientation="horizontal" android:background="#b2c6cb" > <Button android:id="@+id/btn_id1" android:layout_width="40dp" android:layout_height="40dp" android:scaleType="fitCenter" android:layout_gravity="left" android:layout_marginLeft="10dp" android:layout_marginTop="15dp" android:layout_marginBottom="15dp" /> <Button android:id="@+id/btn_id2" android:layout_width="40dp" android:layout_height="40dp" android:scaleType="fitCenter" android:layout_gravity="left" android:layout_marginLeft="10dp" android:layout_marginTop="15dp" android:layout_marginBottom="15dp" /> <Button android:id="@+id/btn_id3" android:layout_width="40dp" android:layout_height="40dp" android:scaleType="fitCenter" android:layout_gravity="right" android:layout_marginLeft="10dp" android:layout_marginTop="15dp" android:layout_marginBottom="15dp" /> <Button android:id="@+id/btn_id4" android:layout_width="40dp" android:layout_height="40dp" android:scaleType="fitCenter" android:layout_gravity="right" android:layout_marginLeft="10dp" android:layout_marginTop="15dp" android:layout_marginBottom="15dp" /> </LinearLayout>
guest

0

ベストアンサー

・RelativeLayoutを使う。
LinearLayoutではなくRelativeLayoutを使うとできます。

・weightを使う。
spaceのlayout_widthを0にし、layout_weightを1にしてください。

・layout_gravityが効かない
LinearLayoutではorientationと同方向へのlayout_gravityは効かないと思います。

投稿2015/10/09 05:13

yona

総合スコア18155

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

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

buibui80

2015/10/09 05:24

ご指定の方法で期待する表示にできました。 LinearLayoutのままでも問題ありませんでした。 ありがとうございました。
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

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

ただいまの回答率
85.47%

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

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

質問する

関連した質問