ここにいくつかの簡単なガイドラインがあります:
- Androidレイアウトは、通常予想されるよりもはるかに深くネストされる傾向があります。多くの場合、他の要素が正しくレイアウトされるようにスペースを占有する「空の」レイアウトになってしまいます。
- テキストを特定の端に揃えるときはいつでも、RelativeLayoutが友達になります。
- パディング設定を使用して、テキストを端から「少し離して」配置します。
- Gravityは、そのTextViewまたはボタン内のテキストを整列させます。
もう一度あなたの図を見て、私はそれをこのように再現しました:
- 画面全体を占める相対レイアウト('fill_content')から始めます。
- 上下に固定して「短いテキスト」と「もう少しテキスト」を入れます。
- 画面中央のポイントに、プロパティ「centerInParent」を含む幅ゼロのアイテムを配置します。
- 残りを上のアイテムに置き、その中心点に合わせます。
残念ながら、ステップ4の何も正しく機能しませんでした。参照されるアイテムがcenterInParentアイテムである場合、「layout_below」のようなものは機能しませんでした。手順3の相対レイアウトを使用します。トップレベルでfill_contentを失敗したことに関係していることがわかりました。はい、レイアウトには注意が必要です。デバッガーがあればいいのにと思います。
正しいバージョンは次のとおりです。
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/r1"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:id="@+id/short_text"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Short Text"
android:gravity="right"
android:layout_marginTop="30dip"
android:layout_alignParentTop="true" />
<TextView
android:id="@+id/more_text"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Some More Text"
android:gravity="center"
android:layout_alignParentBottom="true" />
<TextView android:id="@+id/centerpoint"
android:layout_centerInParent="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:width="0dip"
android:height="0dip"
/>
<TextView android:id="@+id/run_fox"
android:text="Run, fox, run!"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@id/centerpoint"
android:layout_toLeftOf="@id/centerpoint"
/>
<TextView
android:layout_below="@id/centerpoint"
android:text="The quick brown fox jumped over the lazy dog, who had been a frog, and then got features and ran slowly."
android:layout_alignRight="@id/centerpoint"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
</RelativeLayout>