gpt4 book ai didi

Android Togglebuttons 组织成金字塔?

转载 作者:行者123 更新时间:2023-11-29 18:21:55 26 4
gpt4 key购买 nike

我想将 7 个切换按钮组织成金字塔形,如下所示:

---b---
--b-b--
-b---b-
b-----b

其中 b 代表切换按钮,- 代表空格。我也 wnat 整个金字塔来填充它的 parent 的宽度。我怎样才能做到这一点?感谢您的帮助。

最佳答案

使用 RelativeLayout。

使顶部按钮具有 layout_centerHorizo​​ntal="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"
/>

关于Android Togglebuttons 组织成金字塔?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4922527/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com