Android: custom layout for Radio Group(Android:无线电组的自定义布局)
问题描述
我正在尝试创建一个 2x2 单选按钮数组,但我不知道如何自定义除水平或垂直之外的布局.有什么想法吗?
I'm trying to create a 2x2 array of radio buttons, but I don't know how to customize layout other than horizontal or vertical. Any ideas?
我才得到
A B C D
和
A
B
C
D
但我想拥有
A B
C D
我解决了这个问题.对于任何想知道的人,我建立了两个单独的广播组(即一个带有 AB 和一个带有 CD).我为每个 RadioButton 设置了 onClickListener(),并在单击第一个 RadioGroup 中的按钮时在第二个 RadioGroup 上使用 clearCheck(),反之亦然.
I resolved this issue. For anyone wondering, I set up two individual radio groups (i.e. one with AB and one with CD). I set onClickListener() for each RadioButton, and used clearCheck() on the second RadioGroup when a button in the first RadioGroup was clicked, and vice versa.
推荐答案
您可以通过在 RadioGroup
中包含两个 LinearLayout
和 orientation= 来轻松实现水平"
.
You can easily do it by including two LinearLayout
into your RadioGroup
with a orientation="horizontal"
.
<RadioGroup
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAllCaps="true"
android:text="18-24"
/>
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAllCaps="true"
android:text="36-45"
/>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAllCaps="true"
android:text="25-35"
/>
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAllCaps="true"
android:text=">45"
/>
</LinearLayout>
这篇关于Android:无线电组的自定义布局的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Android:无线电组的自定义布局


- 从 finally 块返回时 Java 的奇怪行为 2022-01-01
- Spring Boot连接到使用仲裁器运行的MongoDB副本集 2022-01-01
- value & 是什么意思?0xff 在 Java 中做什么? 2022-01-01
- Java包名称中单词分隔符的约定是什么? 2022-01-01
- 将log4j 1.2配置转换为log4j 2配置 2022-01-01
- Eclipse 插件更新错误日志在哪里? 2022-01-01
- Jersey REST 客户端:发布多部分数据 2022-01-01
- C++ 和 Java 进程之间的共享内存 2022-01-01
- Safepoint+stats 日志,输出 JDK12 中没有 vmop 操作 2022-01-01
- 如何使用WebFilter实现授权头检查 2022-01-01