目次へ
| RelativeLayoutでは、その中に置く部品をParentあるいは、他の部品との位置でしめすことにより、レイアウトします。 |
■■■■ RelativeLayoutの例 ■■■■
次のような画面は下のようなレイアウトファイルを使いました。
レイアウトファイル
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent" >
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:text="ボタン1" />
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/button1"
android:text="ボタン2" />
<Button
android:id="@+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="ボタン3" />
<Button
android:id="@+id/button4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:text="ボタン4" />
<Button
android:id="@+id/button5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toLeftOf="@id/button1"
android:layout_alignParentTop="true"
android:text="ボタン5" />
<Button
android:id="@+id/button6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/button2"
android:layout_below="@id/button2"
android:text="ボタン6" />
</RelativeLayout>
|
Relative Layoutの属性まとめ
親コンテナを基準にする方法と、他の部品を基準にする方法があります。
| 属性 | 値 | 意味 |
| layout_alignParentTop | true | 親コンテナの上端に配置 |
| layout_alignParentBottom | true | 親コンテナの下端に配置 |
| layout_alignParentLeft | true | 親コンテナの左端に配置 |
| layout_alignParentRight | true | 親コンテナの右端に配置 |
| layout_centerHorizontal | true | 親コンテナの水平方向の中央に配置 |
| layout_centerVertical | true | 親コンテナの垂直方向の中央に配置 |
| layout_centerParent | true | 親コンテナの水平垂直の中心に配置 |
| layout_below | "@id/button1" | button1というIDのコンポーネントの下に配置 |
| layout_above | "@id/button1" | button1というIDのコンポーネントの上に配置 |
| layout_toLeftOf | "@id/button1" | button1というIDのコンポーネントの左に配置 |
| layout_toRightOf | "@id/button1" | button1というIDのコンポーネントの右に配置 |
にほんブログ村
0 件のコメント:
コメントを投稿