android - 无法为 RadioButtons 添加边距

标签 android android-layout android-xml android-radiogroup

我的布局有问题。我有一个对话框,我想在其中放置 RadioButtons,但正如您在屏幕截图中看到的那样,它们彼此非常接近。如何拉开他们之间的距离?我已经尝试过 Margin Left/Right、Padding Left/Right 等,但这些都不起作用。

截图

screenshot

我的 .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/

相关文章:

android - 将 arraylist 从一个 Activity 传递到另一个 Activity

java - Android 中的 GridView 中未触发 OnItemClick 事件

android - 在支持多密度的屏幕上设置多个图像

android - 水平放置两个 imageView

android - 将 URI 与 <data> 匹配,例如 AndroidManifest 中的 http ://example. com/something

android - ViewPager 偏移光标位置

android - 将 EditText 调整为字体大小

android - 状态通知的默认 XML

android - RelativeLayout.BELOW 不工作

java - 设置动态壁纸不起作用