lkf181 2023-05-16 16:18 采纳率: 82.5%
浏览 51
已结题

如何让两行RadioButton在一个RadioGroup组里?

为了方便说明 先上一张图

我想达到的效果是红框里的样子,(注意两行是一个RadioGroup组)并且按钮在一行里也较多,需要包在HorizontalScrollView里,现在的问题是:不互斥了!即:都可以选中,但选择同组中的按钮,之前选中的不取消选择,现在红框外的好使。
然后面我分别只把这段代码和整页的完整代码分别贴出来。

img

不好使部分的代码

            <!--RowStart背景颜色和动态背景-->
           <RadioGroup
               android:id="@+id/rgTwoRow_background"
               android:layout_width="wrap_content"
               android:layout_height="wrap_content"
               android:layout_gravity="left"
               >
               <!-- 一行 -->
               <LinearLayout
                   android:layout_width="wrap_content"
                   android:layout_height="wrap_content"
                   android:orientation="vertical"
                  >
                   <TextView
                       android:layout_width="wrap_content"
                       android:layout_height="wrap_content"
                       android:textSize="@dimen/titile_textSize"
                       android:textColor="@color/titile_textColor"
                       android:text="背景颜色:"/>
                   <HorizontalScrollView
                       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:tag="#ffffff"
                               android:layout_width="@dimen/button_width"
                               android:layout_height="@dimen/button_height"
                               android:layout_marginLeft="@dimen/ColumnWidth"
                               android:button="@null"
                               android:background="@drawable/rbtn_ffffff_selector"
                               />
                           <RadioButton

                               android:tag="#000000"
                               android:layout_width="@dimen/button_width"
                               android:layout_height="@dimen/button_height"
                               android:layout_marginLeft="@dimen/ColumnWidth"
                               android:button="@null"
                               android:background="@drawable/rbtn_000000_selector"
                               />
                           <RadioButton

                               android:tag="#01fe29"
                               android:layout_width="@dimen/button_width"
                               android:layout_height="@dimen/button_height"
                               android:layout_marginLeft="@dimen/ColumnWidth"
                               android:button="@null"
                               android:background="@drawable/rbtn_01fe29_selector"
                               />
                           <RadioButton

                               android:tag="#01fec8"
                               android:layout_width="@dimen/button_width"
                               android:layout_height="@dimen/button_height"
                               android:layout_marginLeft="@dimen/ColumnWidth"
                               android:button="@null"
                               android:background="@drawable/rbtn_01fec8_selector"
                               />
                           <RadioButton

                               android:tag="#019efd"
                               android:layout_width="@dimen/button_width"
                               android:layout_height="@dimen/button_height"
                               android:layout_marginLeft="@dimen/ColumnWidth"
                               android:button="@null"
                               android:background="@drawable/rbtn_019efd_selector"/>
                           <RadioButton

                               android:tag="#fd006d"
                               android:layout_width="@dimen/button_width"
                               android:layout_height="@dimen/button_height"
                               android:layout_marginLeft="@dimen/ColumnWidth"
                               android:button="@null"
                               android:background="@drawable/rbtn_fd006d_selector"/>
                           <RadioButton

                               android:tag="#ff0000"
                               android:layout_width="@dimen/button_width"
                               android:layout_height="@dimen/button_height"
                               android:layout_marginLeft="@dimen/ColumnWidth"
                               android:button="@null"
                               android:background="@drawable/rbtn_ff0000_selector"/>
                           <RadioButton

                               android:tag="#ff010c"
                               android:layout_width="@dimen/button_width"
                               android:layout_height="@dimen/button_height"
                               android:layout_marginLeft="@dimen/ColumnWidth"
                               android:button="@null"
                               android:background="@drawable/rbtn_ff010c_selector"/>
                           <RadioButton

                               android:tag="#ff5402"
                               android:layout_width="@dimen/button_width"
                               android:layout_height="@dimen/button_height"
                               android:layout_marginLeft="@dimen/ColumnWidth"
                               android:button="@null"
                               android:background="@drawable/rbtn_ff5402_selector"/>
                           <RadioButton

                               android:tag="#ffe103"
                               android:layout_width="@dimen/button_width"
                               android:layout_height="@dimen/button_height"
                               android:layout_marginLeft="@dimen/ColumnWidth"
                               android:button="@null"
                               android:background="@drawable/rbtn_ffe103_selector"/>


                       </LinearLayout>
                   </HorizontalScrollView>
               </LinearLayout>
               <!-- 一行完毕 -->


               <!-- 一行 -->
               <LinearLayout
                   android:layout_width="wrap_content"
                   android:layout_height="wrap_content"
                   android:orientation="vertical"
                   >
                   <TextView
                       android:layout_width="wrap_content"
                       android:layout_height="wrap_content"
                       android:textSize="@dimen/titile_textSize"
                       android:textColor="@color/titile_textColor"
                       android:text="背景颜色:"/>
                   <HorizontalScrollView
                       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:tag="#ffffff"
                               android:layout_width="@dimen/button_width"
                               android:layout_height="@dimen/button_height"
                               android:layout_marginLeft="@dimen/ColumnWidth"
                               android:button="@null"
                               android:background="@drawable/rbtn_ffffff_selector"
                               />
                           <RadioButton

                               android:tag="#000000"
                               android:layout_width="@dimen/button_width"
                               android:layout_height="@dimen/button_height"
                               android:layout_marginLeft="@dimen/ColumnWidth"
                               android:button="@null"
                               android:background="@drawable/rbtn_000000_selector"
                               />
                           <RadioButton

                               android:tag="#01fe29"
                               android:layout_width="@dimen/button_width"
                               android:layout_height="@dimen/button_height"
                               android:layout_marginLeft="@dimen/ColumnWidth"
                               android:button="@null"
                               android:background="@drawable/rbtn_01fe29_selector"
                               />
                           <RadioButton

                               android:tag="#01fec8"
                               android:layout_width="@dimen/button_width"
                               android:layout_height="@dimen/button_height"
                               android:layout_marginLeft="@dimen/ColumnWidth"
                               android:button="@null"
                               android:background="@drawable/rbtn_01fec8_selector"
                               />
                           <RadioButton

                               android:tag="#019efd"
                               android:layout_width="@dimen/button_width"
                               android:layout_height="@dimen/button_height"
                               android:layout_marginLeft="@dimen/ColumnWidth"
                               android:button="@null"
                               android:background="@drawable/rbtn_019efd_selector"/>
                           <RadioButton

                               android:tag="#fd006d"
                               android:layout_width="@dimen/button_width"
                               android:layout_height="@dimen/button_height"
                               android:layout_marginLeft="@dimen/ColumnWidth"
                               android:button="@null"
                               android:background="@drawable/rbtn_fd006d_selector"/>
                           <RadioButton

                               android:tag="#ff0000"
                               android:layout_width="@dimen/button_width"
                               android:layout_height="@dimen/button_height"
                               android:layout_marginLeft="@dimen/ColumnWidth"
                               android:button="@null"
                               android:background="@drawable/rbtn_ff0000_selector"/>
                           <RadioButton

                               android:tag="#ff010c"
                               android:layout_width="@dimen/button_width"
                               android:layout_height="@dimen/button_height"
                               android:layout_marginLeft="@dimen/ColumnWidth"
                               android:button="@null"
                               android:background="@drawable/rbtn_ff010c_selector"/>
                           <RadioButton

                               android:tag="#ff5402"
                               android:layout_width="@dimen/button_width"
                               android:layout_height="@dimen/button_height"
                               android:layout_marginLeft="@dimen/ColumnWidth"
                               android:button="@null"
                               android:background="@drawable/rbtn_ff5402_selector"/>
                           <RadioButton

                               android:tag="#ffe103"
                               android:layout_width="@dimen/button_width"
                               android:layout_height="@dimen/button_height"
                               android:layout_marginLeft="@dimen/ColumnWidth"
                               android:button="@null"
                               android:background="@drawable/rbtn_ffe103_selector"/>


                       </LinearLayout>
                   </HorizontalScrollView>
               </LinearLayout>
               <!-- 一行完毕 -->



           </RadioGroup>
            <!--    RowEnd背景颜色和动态背景-->

  • 写回答

2条回答 默认 最新

  • aLvXuan 2023-05-17 16:28
    关注

    写不了,但你可以对两个 RadioGroup分别监听,选了其中一个Group,把另一个Group取消掉

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

问题事件

  • 已结题 (查看结题原因) 5月20日
  • 已采纳回答 5月17日
  • 创建了问题 5月16日

悬赏问题

  • ¥15 求帮生成一个lattice diamond的许可证
  • ¥15 大一前端新生求教学解答
  • ¥15 如何制作一个可以查看“网游有序列的装备词条”的软件/插件
  • ¥15 CS2打5E与完美天梯匹配会与服务器断开连接(黑框没标明具体原因)
  • ¥15 利用cst反推材料电磁参数,推出想x,y,z方向的相对介电常数与磁导率
  • ¥15 求帮助!用赛灵思FPGA XC7A35T对一个频率50MHz的数字信号读取高低电平,只用HR bank普通单端io进行采样可以吗
  • ¥15 训练准确率100%,测试准确率只有50%
  • ¥15 grafana创建dashhabord提示no data sources of type Prometheus Alert
  • ¥15 python用arima时间序列法预测不出结果 急
  • ¥15 思科交换机如何恢复配置