Android:无线电组的自定义布局 [英] Android: custom layout for Radio Group

查看:35
本文介绍了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 中包含两个 LinearLayoutorientation= 来轻松实现水平".

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:无线电组的自定义布局的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆