RadioButton 多行 多列显示

布局:

<RadioGroup
            android:id="@+id/rg_first"
            style="@style/rg_style"
            android:orientation="horizontal">

            <RadioButton
                android:id="@+id/pay_issue"
                style="@style/rg_rb_style"
                android:text="@string/pay_issue" />

            <RadioButton
                android:id="@+id/cannot_play"
                style="@style/rg_rb_style"
                android:text="@string/cannot_play" />

        </RadioGroup>

        <RadioGroup
            android:id="@+id/rg_second"
            style="@style/rg_style"
            android:orientation="horizontal">


            <RadioButton
                android:id="@+id/force_closure"
                style="@style/rg_rb_style"
                android:text="@string/force_closure" />

            <RadioButton
                android:id="@+id/play_pause"
                style="@style/rg_rb_style"
                android:text="@string/play_pause" />
        </RadioGroup>

        <RadioGroup
            android:id="@+id/rg_third"
            style="@style/rg_style"
            android:orientation="horizontal">

            <RadioButton
                android:id="@+id/other_issues"
                style="@style/rg_rb_style"
                android:text="@string/other_issues" />
        </RadioGroup>

Java:

public class FeedBackActivity extends BaseActivity implements RadioGroup.OnCheckedChangeListener{
    private RadioGroup firstRG;
    private RadioGroup secondRG;
    private RadioGroup thirdRG;
    public static Intent getFeedBackActivityIntent(Context context){
        Intent feedBackIntent = new Intent(context, FeedBackActivity.class);
       return feedBackIntent;
    }
    @Override
    protected int getLayoutId() {
        return R.layout.aty_feed_back;
    }

    @Override
    protected void afterCreate() {
        firstRG = (RadioGroup) findViewById(R.id.rg_first);
        secondRG = (RadioGroup) findViewById(R.id.rg_second);
        thirdRG = (RadioGroup) findViewById(R.id.rg_third);
        firstRG.setOnCheckedChangeListener(this);
        secondRG.setOnCheckedChangeListener(this);
        thirdRG.setOnCheckedChangeListener(this);
    }
    @Override
    public void onCheckedChanged(RadioGroup group, int checkedId) {
        if(group != null && checkedId>0){
            if(group == firstRG){
                secondRG.clearCheck();
                thirdRG.clearCheck();
            }else if(group == secondRG){
                firstRG.clearCheck();
                thirdRG.clearCheck();
            }else if(group == thirdRG){
                firstRG.clearCheck();
                secondRG.clearCheck();
            }
            group.check(checkedId);
        }
    }
}


color.xml:

<style name="rg_style">
        <item name="android:layout_width">match_parent</item>
        <item name="android:layout_height">wrap_content</item>
    </style>

    <style name="rg_rb_style">
        <item name="android:layout_width">wrap_content</item>
        <item name="android:layout_height">wrap_content</item>
        <item name="android:layout_weight">1</item>
    </style>

效果图:



  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
实现多行多列RadioButton,你可以使用 GridLayout 布局。 GridLayout 是一种灵活的布局,可以在多行多列的网格布局中放置 UI 控件,类似于 HTML 中的表格。你可以使用 `rowCount` 和 `columnCount` 属性来指定行数和列数,然后在布局中添加 RadioButton 控件。 下面是一个简单的多行多列 RadioButton 示例布局: ```xml <GridLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:columnCount="3" android:rowCount="3"> <RadioButton android:id="@+id/radioButton1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Option 1" android:layout_row="0" android:layout_column="0"/> <RadioButton android:id="@+id/radioButton2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Option 2" android:layout_row="0" android:layout_column="1"/> <RadioButton android:id="@+id/radioButton3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Option 3" android:layout_row="0" android:layout_column="2"/> <RadioButton android:id="@+id/radioButton4" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Option 4" android:layout_row="1" android:layout_column="0"/> <RadioButton android:id="@+id/radioButton5" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Option 5" android:layout_row="1" android:layout_column="1"/> <RadioButton android:id="@+id/radioButton6" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Option 6" android:layout_row="1" android:layout_column="2"/> <RadioButton android:id="@+id/radioButton7" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Option 7" android:layout_row="2" android:layout_column="0"/> <RadioButton android:id="@+id/radioButton8" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Option 8" android:layout_row="2" android:layout_column="1"/> <RadioButton android:id="@+id/radioButton9" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Option 9" android:layout_row="2" android:layout_column="2"/> </GridLayout> ``` 在这个布局中,我们使用了一个 3x3 的 GridLayout,然后在每个网格中添加了一个 RadioButton。每个 RadioButton 都有一个唯一的 ID 和一个显示文本,以及一个 `layout_row` 和 `layout_column` 属性,用于指定它们在网格布局中的行和列。你可以根据自己的需要修改行数、列数和 RadioButton 的位置和样式。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值