タイトル
本文 (ScrollView 内に TextView)
ボタン
というダイアログがあるとします。
Layout が
LinearyLayout
ScrollView
TextView
Button
になっているとします。
この場合、LinearyLayout, ScrollView, TextView で
layout_width="fill_parent" を指定すると
こんな残念な感じになります。

ちなみに xml は
- <!--xml version="1.0" encoding="utf-8"?-->
- <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:orientation="vertical"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent"
- android:padding="10dip"
- android:gravity="center"
- android:background="#666666"
- >
- <ScrollView
- android:layout_width="fill_parent"
- android:layout_height="fill_parent"
- android:layout_weight="1"
- >
- <TextView
- android:layout_width="fill_parent"
- android:layout_height="fill_parent"
- android:autoLink="web"
- android:text="Libraroid v5.11.235\n\n対応図書館..."
- />
- </ScrollView>
- <Button
- android:id="@+id/dialog_cancel_about"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="@string/dialog_return"
- android:layout_marginTop="10dip"
- />
- </LinearLayout>
ここで、ScrollView を layout_width="wrap_content"
にします。
するとなぜかダイアログが画面の横幅いっぱいになります。謎。

xml はこうなる
- <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:orientation="vertical"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent"
- android:padding="10dip"
- android:gravity="center"
- android:background="#666666"
- >
- <ScrollView
- // fill_parent -> wrap_content
- android:layout_width="wrap_content"
- android:layout_height="fill_parent"
- android:layout_weight="1"
- >
- ...
- </ScrollView>
- ...
- </LinearLayout>
こうすると、横幅いっぱいになってくれます。
layout_width="200dip" とか固定値にしても横幅は広くなりますが、
これのいいところは、画面の向きを横向きにした場合でもちゃんと
横長のダイアログになってくれるところです。
画面の解像度にもよらないので、マルチデバイスに対応するには
数字で指定するよりいいと思います。
画面いっぱいじゃなく、すこし隙間がほしいなと思って、
ルートの LinearLayout に layout_margin を設定したら
謎なことになりました。

グレーの部分が LinearLayout 部分。
なぜか右と下に padding っぽい隙間が!うーん謎。
ちなみに、xml はこんな感じ。
- <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:orientation="vertical"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent"
- android:padding="10dip"
- android:gravity="center"
- android:background="#666666"
- // add layout_margin
- android:layout_margin="20dip"
- >
- ....
- </LinearLayout>
dialogの幅は謎ですよね。。
返信削除自分は、高さ1pxの透明なTextViewを
android:layout_width="fill_parent"
でしこんで、幅を広げてます。