1.布局
使用一个radioGroup布局方式为vertical,再在里面放两个LinearLayout布局为horizontal,这样在布局上的双列效果就出来了

2.布局代码
使用这个布局后发现所有的raidobutton都可以被选择,变成了多选而且还取消不了
android:id="@+id/rg_group"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="10dp">
android:id="@+id/top_advice_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
android:id="@+id/topic_item_option1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="提个建议"/>
android:id="@+id/topic_item_option2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="出错误啦"/>
android:id="@+id/bottom_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
android:id="@+id/topic_item_option3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="不好用"/>
android:id="@+id/topic_item_option4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:checked="true"
android:text="其他"/>
3.activiy代码
为了解决多选的问题,写了一个更新radioGroup选择条目的方法,这样就可以只选择一个条目了,只用传入你需要被选择的item值即可
/**
* 更新group选择的item
* @param item
*/
private void upGroup(int item){
switch (item){
case 1:
mTopicItemOption1.setChecked(true);
mTopicItemOption2.setChecked(false);
mTopicItemOption3.setChecked(false);
mTopicItemOption4.setChecked(false);
break;
case 2:
mTopicItemOption1.setChecked(false);
mTopicItemOption2.setChecked(true);
mTopicItemOption3.setChecked(false);
mTopicItemOption4.setChecked(false);
break;
case 3:
mTopicItemOption1.setChecked(false);
mTopicItemOption2.setChecked(false);
mTopicItemOption3.setChecked(true);
mTopicItemOption4.setChecked(false);
break;
case 4:
mTopicItemOption1.setChecked(false);
mTopicItemOption2.setChecked(false);
mTopicItemOption3.setChecked(false);
mTopicItemOption4.setChecked(true);
break;
}
}