今日のネタはweightです。
重さが重要なんです。
さっそくxmlです。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<Button android:text="TEST1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<Button android:text="TEST3"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<Button android:text="TEST4"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1" />
<Button android:text="TEST6"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
</LinearLayout>
ボタン、テキストボックス(EditText)、ボタンを要素にもつ
LinearLayoutを2行出します。
この時、テキストボックスの横幅を画面全体にしています。
ただし、2行目はandroid:layout_weight="1"と記載
1行目は右側のボタンが消えてしまいました。
(EditTextに押し出されてしまった。)
2行目はキレイに画面内に収まっています。
android:layout_weight="1"とすると、
余ったスペースを全部使う事を意味します。
また、逆に余ったスペースしか使わないとの意味でもあります。
大きい画像を表示する時などに指定するといいですね。
<LinearLayout
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
>
<ListView
android:id="@+id/listAll"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="1"
>
</ListView>
<ListView
android:id="@+id/listSelect"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="1"
>
</ListView>
</LinearLayout>
上記のようにwidthに0dpiを指定してweightを1にした要素を並べると画面を半々で使えます。
実際にゲームを落として楽しみながら確認してみてください
https://play.google.com/store/apps/details?id=atm.game.hitAndBlowCollection(とうとう宣伝開始w)

