5

タイトルのように、RadioGroup の周りにタイトル付きの境界線を作成することは可能ですか? または、少なくとも無地の境界線...ありがとう

4

1 に答える 1

1

タイトル付きの境界線、わかりません...境界線の上に TextView ウィジェットを追加したいだけかもしれません。しかし、単純な境界線の場合、ラジオ グループの周りに境界線を配置する方法は次のとおりです。これが私の基本的なラジオ グループです (3 つのボタンがあり、水平)。

<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 に答える