次のように、7つのトグルボタンをピラミッドに編成したいと思います。
---b---
--b-b--
-b---b-
b-----b
ここで、bはトグルボタンを表し、-は空のスペースを表します。また、親の幅を埋めるためにピラミッド全体を作成します。どうすればこれを達成できますか?どんな助けでも大歓迎です。
次のように、7つのトグルボタンをピラミッドに編成したいと思います。
---b---
--b-b--
-b---b-
b-----b
ここで、bはトグルボタンを表し、-は空のスペースを表します。また、親の幅を埋めるためにピラミッド全体を作成します。どうすればこれを達成できますか?どんな助けでも大歓迎です。
RelativeLayout を使用します。
上部のボタンを layout_centerHorizontal="true" にすると、上部中央に設定されます。次の行では、両方のボタンに layout_below="@id/id_of_your_top_button" を使用して、両方を一番上のボタンの下に配置し、両方に layout_toLeftOf="@id/id_of_your_top_button" と toRight をそれぞれ使用して、次のようにします。トップボタンの左右に配置されます。3行目と4行目を繰り返すだけです。
例:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<ToggleButton
android:id="@+id/top"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
/>
<ToggleButton
android:id="@+id/second_left"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/top"
android:layout_toLeftOf="@id/top"
/>
<ToggleButton
android:id="@+id/second_right"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/top"
android:layout_toRightOf="@id/top"
/>
<ToggleButton
android:id="@+id/third_left"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/second_left"
android:layout_toLeftOf="@id/second_left"
/>
<ToggleButton
android:id="@+id/third_right"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/second_right"
android:layout_toRightOf="@id/second_right"
/>
<ToggleButton
android:id="@+id/fth_left"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/third_left"
android:layout_toLeftOf="@id/third_left"
/>
<ToggleButton
android:id="@+id/fth_right"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/third_right"
android:layout_toRightOf="@id/third_right"
/>