Android Can';t为单选按钮添加边距
我的布局有问题。我有一个对话框,我想在其中放置单选按钮,但正如你在屏幕截图上看到的那样,它们彼此非常接近。如何扩大他们之间的空间?我已经尝试过左/右边距、左/右填充等,但都不起作用 截图 My.xml文件:Android Can';t为单选按钮添加边距,android,android-layout,android-xml,android-radiogroup,Android,Android Layout,Android Xml,Android Radiogroup,我的布局有问题。我有一个对话框,我想在其中放置单选按钮,但正如你在屏幕截图上看到的那样,它们彼此非常接近。如何扩大他们之间的空间?我已经尝试过左/右边距、左/右填充等,但都不起作用 截图 My.xml文件: 单选按钮在线性布局中并排放置。它们的布局\u宽度设置为wrap\u内容。父级(RadioGroup)也设置为wrap\u content,其两个父级(LinearLayout,及其父级,根LinearLayout元素)也设置为wrap\u content。重力也被设置为居中,因此所有物体都
单选按钮在
线性布局中并排放置
。它们的布局\u宽度
设置为wrap\u内容
。父级(RadioGroup
)也设置为wrap\u content
,其两个父级(LinearLayout
,及其父级,根LinearLayout
元素)也设置为wrap\u content
。重力也被设置为居中,因此所有物体都被重力吸引到屏幕的中心,并保持挤在一起
尝试:
- 将根
元素的LinearLayout
设置为layout\u width
fill\u parent
- 将嵌套的
(放射组的父级)设置为线性布局
(即更改元素类型)相对布局
- 通过添加此属性/值对,为每个
单选按钮设置宽度为33%:
android:layout\u weight=“.33”
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="@drawable/backrepeat_reversed" >
<TextView android:id="@+id/ml_label"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/size"
android:gravity="center"/>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RadioGroup android:id="@+id/radio_group"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center">
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center">
<RadioButton android:id="@+id/rws"
android:layout_width="wrap_content"
android:drawableBottom="?android:attr/listChoiceIndicatorSingle"
android:button="@null"
android:text="@string/sw"
android:gravity="center_horizontal|bottom"
android:layout_height="match_parent"
android:textColor="#000000"
android:textSize="50sp"/>
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center">
<RadioButton android:id="@+id/rwm"
android:layout_width="wrap_content"
android:drawableBottom="?android:attr/listChoiceIndicatorSingle"
android:button="@null"
android:text="@string/mw"
android:gravity="center_horizontal|bottom"
android:layout_height="match_parent"
android:textColor="#000000"
android:textSize="50sp"/>
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center">
<RadioButton android:id="@+id/rwb"
android:layout_width="wrap_content"
android:drawableBottom="?android:attr/listChoiceIndicatorSingle"
android:button="@null"
android:text="@string/bw"
android:gravity="center_horizontal|bottom"
android:layout_height="match_parent"
android:textColor="#000000"
android:textSize="50sp"/>
</LinearLayout>
</RadioGroup>
</LinearLayout>
<TextView android:id="@+id/percent_label"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/percentage"
android:gravity="center"/>
<NumberPicker
android:id="@+id/percent_picker"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
/>
</LinearLayout>
试试看,我觉得这很有帮助。试试填充而不是边距。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="@drawable/backrepeat_reversed" >
<TextView android:id="@+id/ml_label"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/size"
android:gravity="center"/>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RadioGroup android:id="@+id/radio_group"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center">
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center">
<RadioButton android:id="@+id/rws"
android:layout_width="wrap_content"
android:drawableBottom="?android:attr/listChoiceIndicatorSingle"
android:button="@null"
android:text="@string/sw"
android:gravity="center_horizontal|bottom"
android:layout_height="match_parent"
android:textColor="#000000"
android:textSize="50sp"/>
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center">
<RadioButton android:id="@+id/rwm"
android:layout_width="wrap_content"
android:drawableBottom="?android:attr/listChoiceIndicatorSingle"
android:button="@null"
android:text="@string/mw"
android:gravity="center_horizontal|bottom"
android:layout_height="match_parent"
android:textColor="#000000"
android:textSize="50sp"/>
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center">
<RadioButton android:id="@+id/rwb"
android:layout_width="wrap_content"
android:drawableBottom="?android:attr/listChoiceIndicatorSingle"
android:button="@null"
android:text="@string/bw"
android:gravity="center_horizontal|bottom"
android:layout_height="match_parent"
android:textColor="#000000"
android:textSize="50sp"/>
</LinearLayout>
</RadioGroup>
</LinearLayout>
<TextView android:id="@+id/percent_label"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/percentage"
android:gravity="center"/>
<NumberPicker
android:id="@+id/percent_picker"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
/>
</LinearLayout>