5

如标题所示 - 是否可以在 RadioGroup 周围制作带标题的边框?或者至少是一个普通的边界......谢谢

4

1 回答 1

1

标题边框,我不知道...您可能只想在边框上方添加一个 TextView 小部件。但是对于一个普通的边框,这是我如何在我的单选组周围设置边框:这是我的基本单选组(有三个按钮,水平)

<RadioGroup android:id="@+id/myRadioLayout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="38dp"
    android:orientation="horizontal"
    android:elevation="24dp">

    <RadioButton android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/radioBtn1"
        android:text="RadioButton1" android:checked="true"
        style="@android:style/Widget.CompoundButton.RadioButton"
        android:textSize="14sp">
    </RadioButton>



    <RadioButton android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/radioBtn2"
        android:text="RadioButton2"
        style="@android:style/Widget.CompoundButton.RadioButton"
        android:textSize="14sp">
    </RadioButton>

    <RadioButton android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/radioBtn3"
        android:text="RadioButton3" android:checked="true"
        style="@android:style/Widget.CompoundButton.RadioButton"
        android:textSize="14sp">
    </RadioButton>  
</RadioGroup>

因此,如果我想要一个围绕我的单选按钮组的边框,我将一个 xml 文件添加到我的可绘制文件夹中。我们称之为“border.xml”。这是border.xml的代码:

<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <stroke android:width="5px" android:color="#000000" />
</shape>

然后,将以下代码添加到单选组 xml:

<RadioGroup android:id="@+id/myRadioLayout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="38dp"
    android:orientation="horizontal"
    android:background="@drawable/border"
    android:elevation="24dp">

您的广播组周围应该会出现一个边框。请注意,您可以更改属性以获得边框、渐变、圆角等的不同形状。形状元素的可能属性可以在此处找到:

https://developer.android.com/guide/topics/resources/drawable-resource.html#Shape

于 2016-11-05T21:47:04.873 回答