我的布局有问题。我有一个对话框,我想在其中放置 RadioButtons,但正如您在屏幕截图中看到的那样,它们彼此非常接近。如何拉开他们之间的距离?我已经尝试过 Margin Left/Right、Padding Left/Right 等,但这些都不起作用。
截图
我的 .xml 文件:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
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">
<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"/>
<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"/>
<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"/>
</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>
最佳答案
单选按钮并排放置在 LinearLayout
中。他们将 layout_width
设置为 wrap_content
。父级(RadioGroup
)也设置为 wrap_content
,它的两个父级(LinearLayout
,以及它的父级,根 LinearLayout
元素)也设置为 wrap_content
。重力也设置为居中,因此一切都被吸引到屏幕的中心,并保持挤在一起。
尝试:
- 将根
LinearLayout
元素的layout_width
设置为fill_parent
。 - 将嵌套的
LinearLayout
(RadioGroup
的父级)设置为RelativeLayout
(即更改元素类型) - 通过添加以下属性/值对为每个
RadioButton
设置宽度为 33%:android:layout_weight=".33"
关于android - 无法为 RadioButtons 添加边距,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26240358/