问题描述
我有一个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实现这一目标。
- 创建
RadioGroup中
与的android:方向=横向
- 把2个单选按钮在里面。
- 创建另一个
RadioGroup中
同上。 - 确保的标识
RadioGroups
和单选按钮
是不同的。 -
使用
setOnCheckedChangeListener
设置相同OnCheckedChangeListener
两个组。//假设活动实现OnCheckedChangeListener
rg1.setOnCheckedChangeListener(本);
rg2.setOnCheckedChangeListener(本); -
通话
clearCheck
其他单选组(第1组,如果支票组已执行2) - 检查这两个群体的检查
单选
在执行的操作。
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'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
- create
RadioGroup
withandroid:orientation = "horizontal"
- put 2 radio buttons in it.
- create another
RadioGroup
same as above. - make sure Id of
RadioGroups
andRadioButtons
are distinct. use
setOnCheckedChangeListener
to set sameOnCheckedChangeListener
on both the groups.//assuming activity implements OnCheckedChangeListenerrg1.setOnCheckedChangeListener(this);rg2.setOnCheckedChangeListener(this);
call
clearCheck
on other radio group (group 1 if check has been performed in group 2)- check both groups for a checked
RadioButton
while performing an operation .
这篇关于如何对齐单选按钮在RadioGroup中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!