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:无线电组的自定义布局
基础教程推荐
- Struts2 URL 无法访问 2022-01-01
- 如何对 Java Hashmap 中的值求和 2022-01-01
- 使用堆栈算法进行括号/括号匹配 2022-01-01
- 无法复制:“比较方法违反了它的一般约定!" 2022-01-01
- REST Web 服务返回 415 - 不支持的媒体类型 2022-01-01
- 问题http://apache.org/xml/features/xinclude测试日志4j 2 2022-01-01
- RabbitMQ:消息保持“未确认"; 2022-01-01
- 存储 20 位数字的数据类型 2022-01-01
- Spring AOP错误无法懒惰地为此建议构建thisJoinPoin 2022-09-13
- 修改 void 函数的输入参数,然后读取 2022-01-01
