android - 使单选按钮图标居中
问题描述
这 。文本居中,而不是图标。我需要图标和文本居中
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RadioGroup
android:layout_width="match_parent"
android:orientation="horizontal"
android:layout_height="wrap_content" >
<RadioButton
android:layout_gravity="center"
android:layout_weight="1"
android:gravity="center"
android:text="Test1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<RadioButton
android:layout_gravity="center"
android:layout_weight="1"
android:text="Test2"
android:gravity="center"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<RadioButton
android:layout_gravity="center"
android:layout_weight="1"
android:text="Test3"
android:gravity="center"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</RadioGroup>
解决方案
你可以试试下面的代码
<?xml version="1.0" encoding="utf-8"?>
<RadioGroup xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:orientation="horizontal">
<RadioButton
android:text="Test1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:orientation="horizontal">
<RadioButton
android:text="Test2"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:orientation="horizontal">
<RadioButton
android:text="Test3"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
</RadioGroup>
推荐阅读
- regex - 我可以在 vscode 的代码段中排除积极的前瞻和后视吗?
- r - equivalent of melt+reshape that splits on column names
- git - 将一个分支合并到另一个分支的文件夹中
- java - 如何通过java中的rest服务获取用户ip
- powershell - Powershell 重用 Get-Help -showwindow
- c# - c#如何初始化或设置默认构造函数值到类的注入依赖项
- entity-framework - EF 动态包含无法按预期工作
- swift - 从 iOS 13 Beta 3 开始,我的应用只显示黑色窗口
- javascript - 如何使用 useState 然后在 React 中执行具有最新状态的函数?
- jquery - 无法在 ajax 中使用表单序列化上传文件