Android切换按钮组织成金字塔?
我想将7个切换按钮组织成一个金字塔,如下所示:Android切换按钮组织成金字塔?,android,layout,togglebutton,Android,Layout,Togglebutton,我想将7个切换按钮组织成一个金字塔,如下所示: ---b--- --b-b-- -b---b- b-----b 其中,b表示切换按钮,-表示空白。我还画了整个金字塔,以填充其父金字塔的宽度。我怎样才能做到这一点?感谢您的帮助。请使用RelativeLayout 使顶部按钮具有布局_centerHorizontal=“true”,并将设置在顶部中间。 对于下一行,使用layout_down=“@id/id_of_your_top_button”两个按钮,以便它们都将在顶部按钮下方对齐,然后,分
---b---
--b-b--
-b---b-
b-----b
其中,b表示切换按钮,-表示空白。我还画了整个金字塔,以填充其父金字塔的宽度。我怎样才能做到这一点?感谢您的帮助。请使用RelativeLayout
使顶部按钮具有布局_centerHorizontal=“true”,并将设置在顶部中间。
对于下一行,使用layout_down=“@id/id_of_your_top_button”两个按钮,以便它们都将在顶部按钮下方对齐,然后,分别使用layout_toLeftOf=“@id/id_of_of_your_top_button”和toRight,以便它们将位于顶部按钮的左侧和右侧。重复第三排和第四排
例如:
<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"
/>
谢谢!工作起来像一个符咒……几乎……但左、右fth_不适合父项的宽度:(如何将所有按钮设置为具有相同的宽度并填充父按钮的宽度?我能给您的唯一快速建议是,计算活动中ToggleButton的宽度并布局金字塔程序,将ToggleButtons中的所有wrap_内容替换为任何宽度值。