Android_UI开发总结(一):RadioButton与RadioGroup使用

2023-11-19

关于RadioButton与RadioGroup的API详解>
https://www.cnblogs.com/Im-Victor/p/6238437.html
下面记录在使用RadioButton和RadioGroup中遇到的三点问题:
1. RadioButton中如何保持文字和选择图标之间合理的间距问题。
这里写图片描述
比如上图中,要确保文字乌拉圭和选项框之间留有一定的间隔,这样UI上更美观。附上代码:

 <TextView
                    android:id="@+id/test"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginStart="15dp"
                    android:layout_marginTop="15dp"
                    android:text="俄罗斯世界杯乌拉圭VS法国"
                    android:textColor="?attr/textColorContentTitle"
                    android:textSize="18sp"
                    app:layout_constraintStart_toStartOf="parent"
                    app:layout_constraintTop_toBottomOf="@+id/detail_split_line1" />

                <RadioGroup
                    android:id="@+id/rg_call_voice_desc"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="8dp"
                    android:orientation="horizontal"
                    app:layout_constraintEnd_toEndOf="parent"
                    app:layout_constraintHorizontal_bias="0.0"
                    app:layout_constraintStart_toStartOf="parent"
                    app:layout_constraintTop_toBottomOf="@+id/test">

                    <RadioButton
                        android:id="@+id/group"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_marginStart="15dp"
                        android:layout_marginTop="2dp"
                        android:background="@null"
                        android:button="@null"
                        android:checked="true"
                        android:drawableLeft="@drawable/radio_button_picture"
                        android:drawablePadding="8dp"
                        android:text="乌拉圭"
                        android:textColor="?attr/textColorContentTitle"
                        android:textSize="18sp" />

                    <RadioButton
                        android:id="@+id/rg_group_call_mute"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_marginStart="36dp"
                        android:layout_marginTop="2dp"
                        android:background="@null"
                        android:button="@null"
                        android:drawableLeft="@drawable/radio_button_picture"
                        android:drawablePadding="8dp"
                        android:text="法国"
                        android:textColor="?attr/textColorContentTitle"
                        android:textSize="18sp"
                        />
                </RadioGroup>

UI布局代码中,要实现选项框和文字之间间距,最重要的代码是:

android:background="@null"
android:button="@null"  android:drawableLeft="@drawable/radio_button_picture"
android:drawablePadding="8dp"

其中background标签限定radiobutton没有背景,如果不设置为null,系统会为button默认设置一个空白背景。drawableleft标签代表的是选项框的样式。drawablePadding代表的是文字到选项框的距离。如果没有设置button和background为null,这里的drawablePadding是不会生效的。

  1. RadioButton如何结合RadioGroup实现多个单选功能。
    单独的RadioButton叠加使用可以实现多选,但是如果要多个RadioButton之间相互排斥,只能选择一个,那么就得像上诉代码一样,在RadioButton之外再包裹一层radiogroup。可以在其中一个RadioButton中设置android:checked=”true”代表当前Button在UI上是默认选中的。
  2. 多个RadioGroup(每个RadioGroup中包含多个RadioButton)如何保持子控件上下左右对齐。
    这里写图片描述
    代码片段如下:
<android.support.constraint.ConstraintLayout
                android:id="@+id/layout"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="@color/1"
                android:orientation="horizontal"
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintHorizontal_bias="0.0"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toBottomOf="@+id/top_layout"
                app:layout_constraintVertical_bias="0.0">

                <TextView
                    android:id="@+id/tv_desc"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginStart="15dp"
                    android:layout_marginTop="15dp"
                    android:text="俄罗斯世界杯巴西VS比利时"
                    android:textColor="?attr/textColorContentTitle"
                    android:textSize="18sp"
                    app:layout_constraintStart_toStartOf="parent"
                    app:layout_constraintTop_toTopOf="parent" />

                <RadioGroup
                    android:id="@+id/rg_call_desc"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="8dp"
                    android:orientation="horizontal"
                    app:layout_constraintEnd_toEndOf="parent"
                    app:layout_constraintHorizontal_bias="0.0"
                    app:layout_constraintStart_toStartOf="parent"
                    app:layout_constraintTop_toBottomOf="@+id/tv_desc">

                    <RadioButton
                        android:id="@+id/rg_normal"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_marginStart="15dp"
                        android:layout_marginTop="2dp"
                        android:background="@null"
                        android:button="@null"
                        android:checked="true"
                        android:drawableLeft="@drawable/radio_button_picture"
                        android:drawablePadding="8dp"
                        android:text="巴西"
                        android:textColor="?attr/textColorContentTitle"
                        android:textSize="18sp" />

                    <RadioButton
                        android:id="@+id/rg_x"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_marginStart="36dp"
                        android:layout_marginTop="2dp"
                        android:background="@null"
                        android:button="@null"
                        android:drawableLeft="@drawable/radio_y"
                        android:drawablePadding="8dp"
                        android:text="比利时"
                        android:textColor="?attr/textColorContentTitle"
                        android:textSize="18sp" />

                </RadioGroup>

                <View
                    android:id="@+id/line1"
                    android:layout_width="0dp"
                    android:layout_height="1dp"
                    android:layout_marginTop="15dp"
                    android:background="?attr/splitLineColor"
                    app:layout_constraintEnd_toEndOf="parent"
                    app:layout_constraintLeft_toLeftOf="parent"
                    app:layout_constraintRight_toRightOf="parent"
                    app:layout_constraintStart_toStartOf="parent"
                    app:layout_constraintTop_toBottomOf="@+id/rg_desc" />

                <TextView
                    android:id="@+id/tv_desc"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginStart="15dp"
                    android:layout_marginTop="15dp"
                    android:text="俄罗斯世界杯乌拉圭VS法国"
                    android:textColor="?attr/textColorContentTitle"
                    android:textSize="18sp"
                    app:layout_constraintStart_toStartOf="parent"
                    app:layout_constraintTop_toBottomOf="@+id/group_detail_split_line1" />

                <RadioGroup
                    android:id="@+id/rg_call_voice_desc"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="8dp"
                    android:orientation="horizontal"
                    app:layout_constraintEnd_toEndOf="parent"
                    app:layout_constraintHorizontal_bias="0.0"
                    app:layout_constraintStart_toStartOf="parent"
                    app:layout_constraintTop_toBottomOf="@+id/tv_desc">

                    <RadioButton
                        android:id="@+id/rg_xx"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_marginStart="15dp"
                        android:layout_marginTop="2dp"
                        android:background="@null"
                        android:button="@null"
                        android:checked="true"
                        android:drawableLeft="@drawable/radio_button_picture"
                        android:drawablePadding="8dp"
                        android:text="乌拉圭"
                        android:textColor="?attr/textColorContentTitle"
                        android:textSize="18sp" />

                    <RadioButton
                        android:id="@+id/rg_yy"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_marginStart="36dp"
                        android:layout_marginTop="2dp"
                        android:background="@null"
                        android:button="@null"
                        android:drawableLeft="@drawable/radio_button_picture"
                        android:drawablePadding="8dp"
                        android:text="法国"
                        android:textColor="?attr/textColorContentTitle"
                        android:textSize="18sp"
                        />
                </RadioGroup>

这里发现布局设置的宽度和大小都是一样的,但是上下的比利时和法国按钮并没有左对齐。
此时打开手机设置>开发者选项>显示布局边界发现:

这里写图片描述
这里白色区域为文字,打码去掉,主要看上下的布局,发现每个group中的button之间的间距是一致的,就是后面两个button上下没有左对齐。
这里暂时没有调整好,思路是在RadioGroup中创建一个相对布局。等调整好了再附上。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Android_UI开发总结(一):RadioButton与RadioGroup使用 的相关文章

  • 设置无线电输入的样式

    所以我在设计单选按钮时遇到了很大的麻烦 因此我设法让它在 Chrome 中完美运行 在 Firefox 中运行得很好 在 IE 中则完全不行 This is the expected look in Chrome This is how i
  • 禁用单选按钮单击上的下拉框

    我有两个单选按钮和一个下拉框 如下所示 我想做的是 1 选中 否 时 隐藏或灰显下拉框 然后 2 当选中 是 时 显示下拉框 任何指示将不胜感激 td td
  • Angular 2:如何从枚举创建单选按钮并添加双向绑定?

    我正在尝试使用 Angular2 语法从枚举定义创建单选按钮 并将值绑定到具有该枚举类型的属性 我的 html 包含 div class from elem div
  • RadioGroup 扩展relativelayout?

    我正在尝试为我的应用程序制作一个单选按钮网格 据我所知 使用常规方法这是不可能的RadioGroup因为它扩展了 LinearLayout 并且如果你尝试安排RadioButtons在里面使用RelativeLayoutRadioGroup
  • Drupal CCK 的复选框

    我是 Drupal 的新人 到目前为止很喜欢 我正在创建 CCK 自定义内容类型 我需要以复选框格式制作便利设施列表 所以我做了 文件类型 Text 小部件类型 复选框 单选按钮 和允许值列表 onsite dining 现场用餐 Meet
  • 在 React 中设置单选按钮值

    我正在制作一个简单的反应应用程序 其表单具有单选按钮 这里有一个可用的默认数据 例如 const defaultData ContactMode 3 ContactMode 2 ContactMode 2 要求 gt 需要迭代这个defau
  • 如何在没有表单的情况下循环遍历单选按钮组?

    如何在 JavaScript 或 jQuery 中循环访问没有表单的单选按钮组 像这样的事情怎么办 使用 jQuery input radio each function if this is checked You have a chec
  • 动态加载用户控件 ASP.net 中的单选选项 GroupName 问题

    我有用户控制 table tr td td tr table
  • 带有react-hook-form的单选按钮

    我用react hook form创建了一个表单 它在控制台中正确记录 fullName 和 city 但不记录单选按钮 使用单选按钮 您会得到结果 null 我的代码如下 import React from react import Ap
  • 自定义 ListView 与 RadioButton 单选

    我希望你们中的一些人可以帮助我解决这个问题 我有一个自定义列表视图 2 个文本视图和 1 个单选按钮 我想把它作为单一选择 但每次我 单击列表视图上的项目 它不会删除该项目 从另一个单选按钮 检查 我的xml代码
  • Python tkinter 通过单选按钮输入小部件状态切换

    一个简单的问题 对于像我这样的 tkinter 新手来说不是那么简单 我正在构建一个 GUI 我想要有两个单选按钮来驱动 Entry 小部件的状态 启用或禁用 用户将在其中输入数据 当按下第一个单选按钮时 我希望禁用该条目 当按下第二个单选
  • 取消选中单选按钮[重复]

    这个问题在这里已经有答案了 该应用程序是一个步进音序器应用程序 具有 16 个无线电组 每组有 8 个按钮 它工作得很好 除非一个组选择了一个按钮 否则我无法将其关闭 除非我使用我创建的清除按钮来清除所有无线电组 我想添加的是一些代码 它表
  • 如何使用 State Hook 在 React 中编写语义 UI 单选组?

    我正在尝试使用 React 中的 Semantic UI 编写一个单选按钮组 我可以在以下位置获取无线电组示例广播页面 https react semantic ui com addons radio 语义 UI 的工作 它是通过扩展来写的
  • 关于http://stackoverflow.com/questions/2381560/how-to-group-a-3x3-grid-of-radio-buttons

    我尝试使用标题中显示的网站上作为第一个答案提供的代码 尽管我尝试修改它 但我无法使其工作 问题是 当我检查第一个单选按钮以外的单选按钮时 它们都会保持选中状态 问题是 什么时候调用 addView 方法 另外 这是我的代码版本 我希望有人能
  • 根据所选单选按钮显示控件

    我有一组三个单选按钮 根据选择的单选按钮 我想显示三个控件之一 文本框 下拉列表或按钮 如何根据所选单选按钮的结果显示控件 您可以使用以下方法将控件的可见性绑定到 RadioButton 的 IsChecked 属性 BooleanToVi
  • 更改所选单选按钮标签的样式

    我试图在表单中选择单选按钮标签时更改其边框颜色 我发现这个问题几乎正是我想要做的 CSS 如何设置选定单选按钮标签的样式 https stackoverflow com questions 4641752 css how to style
  • 即使在回发后也保持用户检查 radiobtn 检查

    我有以下无线电控件 默认选中 全部 如果用户检查其他一些单选按钮并提交 在回发时我想保留选中的按钮 以便用户可以看到他们单击的内容 如何保留使用 jquery 选择的内容 我正在使用的是
  • 如何设计一个在 Firefox、Chrome 和 IE11 中看起来相同的单选按钮

    我想设计一组单选按钮 它们在 Chrome Firefox 和 IE 11 中看起来应该相同 我的解决方案在 Firefox 中看起来相当不错 在 Chrome 中 按钮周围有一个蓝色框 而在 IE 11 中 颜色和边框似乎无法识别 它应该
  • Chrome 21 不检查单选按钮

    我经过一番努力才发现这一点 所以我想我应该分享我所遇到的事情 这样其他人就可以从我的努力中受益 Firefox IE 和 chrome 19 我手边唯一的其他版本 没有这个问题 但 chrome 21 有 如果您有这个单选按钮
  • 单选按钮文本对齐问题

    我正在 asp net 中工作 并且有单选按钮列表 我想根据需要对齐它们的文本 这是我目前拥有的 我想让它们像这样 EDIT 其次 当我单击 Ages From 单选按钮时 我会显示一个 div 如下所示 当我单击返回 All Ages 单

随机推荐

  • html+css+javascript 之间的关系与作用

    三者间的关系 一个基本的网站包含很多个网页 一个网页由 html css 和 javascript 组成 html 是主体 装载各种 dom 元素 css 用来装饰 dom 元素 javascript 控制 dom 元素 用一扇门比喻三者间
  • springboot多模块打包配置问题

    工程案例结构 baidu 聚合过程 baidu web 子模块web工程 baidu service 子模块 baidu config 子模块配置工程 注意事项 配置步骤 1 baidu 聚合工程 工程下的 pom xml 文件案列如下
  • 【云原生之k8s】K8s 管理工具 kubectl 详解(二)

    K8S模拟项目 Kubectl是管理k8s集群的命令行工具 通过生成的json格式传递给apiserver进行创建 查看 管理的操作 帮助信息 root localhost bin kubectl help kubectl controls
  • mysqlbinglog基于即时点还原

    mysqlbinglog基于即时点还原 mysqlbinlog介绍 要想从二进制日志恢复数据 你需要知道当前二进制日志文件的路径和文件名 一般可以从选项文件 即my cnf or my ini 取决于你的系统 中找到路径 mysql5 7开
  • SAR成像系列:【3】合成孔径雷达(SAR)的二维回波信号与简单距离多普勒(RD)算法 (附matlab代码)

    合成孔径雷达发射信号以线性调频信号 LFM 为基础 目前大部分合成孔径雷达都是LFM体制 为了减轻雷达重量也采用线性调频连续波 FMCW 体制 为了获得大带宽亦采用线性调频步进频 FMSF 体制 1 LFM信号 LFM的主要特点在于可以使载
  • 操作系统内存管理——分区、页式、段式、段页式管理

    1 内存管理方法 内存管理主要包括虚地址 地址变换 内存分配和回收 内存扩充 内存共享和保护等功能 2 连续分配存储管理方式 连续分配是指为一个用户程序分配连续的内存空间 连续分配有单一连续存储管理和分区式储管理两种方式 2 1 单一连续存
  • 谈谈Qt信号与槽

    关于Qt信号与槽 Qt信号与槽本质类似观察者模式 观察者模式 Observer Pattern 定义对象间的一种一对多依赖关系 使得每当一个对象状态发生改变时 其相关依赖对象皆得到通知并被自动更新 观察者模式又叫做发布 订阅 Publish
  • 5G Capital一年,“首都标准”初现

    在北京生活许多年 如果问我什么时候京味浓度最高 答案可能是下了飞机 走上出租车的那一刻 北京司机连闲聊都是一副见过世面的样子 你研究人工智能 我觉得吧交通管理就该这样那样 高铁咱都造出来了 什么高科技我看中国人很快就能搞出来 冬奥会场馆建得
  • scatter函数绘制散点图——MATLAB

    1 scatter X Y 在矢量X和Y指定的位置显示彩色圆 如 scatter 1 2 3 4 4 5 6 7 效果如图 默认彩色圆为蓝色空心圆 2 scatter X Y S S确定每个标记的面积 S可以是与X和Y相同长度的矢量或标量
  • Gibbs 采样基本原理和仿真

    Gibbs 采样基本原理和仿真 文章目录 Gibbs 采样基本原理和仿真 1 基本概念 1 1 Gibbs采样算法 1 2 Markov链 1 2 1 Markov链的定义 1 2 2 Markov链的细致平稳条件 1 2 3 Markov
  • 初学者怎么高效率学习c语言?

    想学C语言我们首先的了解C语言是什么 它是一门面向过程的 抽象化的通用程序设计语言 广泛应用于底层开发 C语言能以简易的方式编译以及处理低级存储器 C语言是仅产生少量的机器语言以及不需要任何运行环境支持就可以运行的高效率程序设计语言 尽管C
  • ubuntu 11配置hadoop

    最近没事 研究下ubuntu 配置hadoop ubuntu版本 64 bit 11 04 hadoop版本 hadoop1 2 1 一 在Ubuntu下创建hadoop用户组和用户 1 创建hadoop用户组 sudo addgroup
  • Samy XSS Worm 分析

    Samy Worm MySpace com允许用户通过控制标签的style属性 samy构造css xss MySpace过滤了很多关键字 利用拆分法绕过 div标签如下 div div 其中expr字符串的内容为如下javascript代
  • 软件质量保证与测试技术实验报告(二)黑盒测试用例设计

    1 实验名称 黑盒测试用例设计 2 实验目的 学会用等价类划分法和边界值法设计测试用例 进行功能测试 3 实验内容 题目1 NextDate程序的功能是按年 月 日的顺序输入一个日期 输出为输入日期后一天的日期 请使用等价类和边界值法对Ne
  • windows内核驱动开发(WDK环境搭建)

    去官网下载WDK安装包和Visual Studio 下载 Windows 驱动程序工具包 WDK Windows drivers Microsoft Docs 首先安装Visual Studio 这个就不用我介绍了怎么安装了 下面直接下载步
  • JESD204B(RX)协议接口说明。

    解释一下Vivado IP协议中的Shared Logic in Example 与 Shared Logic in Core 首先 什么是Shared Logic 字面意思很好理解 就是共享逻辑 主要包括时钟 复位等逻辑 当选择Share
  • grafana elasticsearch es 创建变量variable时,query里的查询语句是对的,但是预览没有数据

    问题 图中的query输入框中输入正确 并且es中有rulename字段 rulename也有值 但是此处预览里没有值 按F12看了grafana的请求体和响应体才发现 rulename是text类型的 不能进行聚集 所以这里查不到数据 解
  • -离散数学-期末练习题解析

    一 选择题 二 填空题 三 计算题 四 简答题 五 证明题 六 应用题 一 选择题 下列句子中 是命题 A 2是常数 B 这朵花多好看啊 C 请把们关上 D 下午有会吗 A 命题是能判断真假的陈述句 B是感叹句 C是祈使句 D是疑问句 令p
  • sqlserver开启sql登录方式!

    安装sqlserver的时候只有windows登录 但有时也要用到sqlserver登录的方式 总不可能重新安装sqlserver吧 1 先用windows登录sqlserver 依次单击 安全性 gt 登录名 gt sa 右键打开sa的属
  • Android_UI开发总结(一):RadioButton与RadioGroup使用

    关于RadioButton与RadioGroup的API详解 gt https www cnblogs com Im Victor p 6238437 html 下面记录在使用RadioButton和RadioGroup中遇到的三点问题 1