如何对齐单选按钮在RadioGroup中 [英] How to align radiobuttons in a radiogroup

查看:241
本文介绍了如何对齐单选按钮在RadioGroup中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个RadioGroup中,其中我有4个单选按钮在它。我想作为两条水平线即2单选按钮水平和另外两个单选按钮水平和下方的第一水平单选按钮它们被对齐。

我怎样才能做到这一点,而不改变其功能。

这意味着只有一个单选按钮可以选择。

下面是我简单的code:

 < RadioGroup中
    机器人:ID =@ + ID / radiogroup_relation_options
    机器人:layout_width =match_parent
    机器人:layout_height =WRAP_CONTENT
    机器人:layout_below =@ ID / HeadingText
    机器人:背景=#4269c6>    <的LinearLayout
        机器人:layout_width =match_parent
        机器人:layout_height =WRAP_CONTENT>        <的LinearLayout
            机器人:layout_width =WRAP_CONTENT
            机器人:layout_height =WRAP_CONTENT
            机器人:layout_weight =1
            机器人:方向=垂直>            <单选
                机器人:ID =@ + ID / radiobutton_friend
                机器人:layout_width =WRAP_CONTENT
                机器人:layout_height =WRAP_CONTENT
                机器人:layout_marginLeft =10dp
                机器人:layout_marginTop =5DP
                机器人:按钮=@绘制/ custom_radiobutton
                机器人:填充=5DP
                机器人:paddingLeft =10dp
                机器人:文字=朋友
                机器人:TEXTSIZE =15sp/>            <单选
                机器人:ID =@ + ID / radiobutton_business
                机器人:layout_width =WRAP_CONTENT
                机器人:layout_height =WRAP_CONTENT
                机器人:layout_marginLeft =10dp
                机器人:layout_marginTop =5DP
                机器人:按钮=@绘制/ custom_radiobutton
                机器人:填充=5DP
                机器人:paddingLeft =10dp
                机器人:文字=我们和放大器;者;已经做到一起做生意
                机器人:TEXTSIZE =15sp/>
        < / LinearLayout中>        <的LinearLayout
            机器人:layout_width =WRAP_CONTENT
            机器人:layout_height =WRAP_CONTENT
            机器人:layout_weight =1
            机器人:方向=垂直>            <单选
                机器人:ID =@ + ID / radiobutton_colleague
                机器人:layout_width =WRAP_CONTENT
                机器人:layout_height =WRAP_CONTENT
                机器人:layout_marginLeft =10dp
                机器人:layout_marginTop =5DP
                机器人:按钮=@绘制/ custom_radiobutton
                机器人:填充=5DP
                机器人:paddingLeft =10dp
                机器人:文字=同事
                机器人:TEXTSIZE =15sp/>            <单选
                机器人:ID =@ + ID / radiobutton_other
                机器人:layout_width =WRAP_CONTENT
                机器人:layout_height =WRAP_CONTENT
                机器人:layout_marginLeft =10dp
                机器人:layout_marginTop =5DP
                机器人:按钮=@绘制/ custom_radiobutton
                机器人:填充=5DP
                机器人:paddingLeft =10dp
                机器人:文字=其他
                机器人:TEXTSIZE =15sp/>
        < / LinearLayout中>
    < / LinearLayout中>
< / RadioGroup中>


解决方案

您可以通过使用2 radioGroups实现这一目标。


  1. 创建 RadioGroup中的android:方向=横向

  2. 把2个单选按钮在里面。

  3. 创建另一个 RadioGroup中同上。

  4. 确保的标识 RadioGroups 单选按钮是不同的。

  5. 使用 setOnCheckedChangeListener 设置相同 OnCheckedChangeListener 两个组。

    //假设活动实现OnCheckedChangeListener
    rg1.setOnCheckedChangeListener(本);
    rg2.setOnCheckedChangeListener(本);


  6. 通话 clearCheck 其他单选组(第1组,如果支票组已执行2)


  7. 检查这两个群体的检查单选在执行的操作。

I have a radiogroup in which I have 4 radiobuttons in it.I want them to be align as a two horizontal lines i.e two radiobuttons horizontally and other two radiobuttons horizontally and below the first horizontal radiobuttons.

How can i accomplish this without changing its functionality

It means only one radiobutton can be selected.

Here's my simple code:

<RadioGroup
    android:id="@+id/radiogroup_relation_options"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_below="@id/HeadingText"
    android:background="#4269c6" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:orientation="vertical" >

            <RadioButton
                android:id="@+id/radiobutton_friend"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="10dp"
                android:layout_marginTop="5dp"
                android:button="@drawable/custom_radiobutton"
                android:padding="5dp"
                android:paddingLeft="10dp"
                android:text="Friend"
                android:textSize="15sp" />

            <RadioButton
                android:id="@+id/radiobutton_business"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="10dp"
                android:layout_marginTop="5dp"
                android:button="@drawable/custom_radiobutton"
                android:padding="5dp"
                android:paddingLeft="10dp"
                android:text="We&apos;ve done Business Together"
                android:textSize="15sp" />
        </LinearLayout>

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:orientation="vertical" >

            <RadioButton
                android:id="@+id/radiobutton_colleague"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="10dp"
                android:layout_marginTop="5dp"
                android:button="@drawable/custom_radiobutton"
                android:padding="5dp"
                android:paddingLeft="10dp"
                android:text="Colleague"
                android:textSize="15sp" />

            <RadioButton
                android:id="@+id/radiobutton_other"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="10dp"
                android:layout_marginTop="5dp"
                android:button="@drawable/custom_radiobutton"
                android:padding="5dp"
                android:paddingLeft="10dp"
                android:text="Other"
                android:textSize="15sp" />
        </LinearLayout>
    </LinearLayout>
</RadioGroup>

解决方案

you can achieve this by using 2 radioGroups

  1. create RadioGroup with android:orientation = "horizontal"
  2. put 2 radio buttons in it.
  3. create another RadioGroup same as above.
  4. make sure Id of RadioGroups and RadioButtons are distinct.
  5. use setOnCheckedChangeListener to set same OnCheckedChangeListener on both the groups.

    //assuming activity implements OnCheckedChangeListener rg1.setOnCheckedChangeListener(this); rg2.setOnCheckedChangeListener(this);

  6. call clearCheck on other radio group (group 1 if check has been performed in group 2)

  7. check both groups for a checked RadioButton while performing an operation .

这篇关于如何对齐单选按钮在RadioGroup中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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