3

RadioButton の background プロパティを変更中に問題が発生しました

まず、1つのラジオボタングループの3つである各ラジオボタンの下に線を作成したい

ここに以下のコードがあります

 <RadioGroup
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:divider="@android:color/black"
    android:orientation="vertical" >

    <RadioButton
        android:id="@+id/radioBtnFirst"
        android:layout_width="fill_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:background="@drawable/custom_radiogroup_divider"
        android:text="Answer 1"/>

    <RadioButton
        android:id="@+id/radioBtnTwo"
        android:layout_width="fill_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:background="@drawable/custom_radiogroup_divider"
        android:text="Answer 2"/>

    <RadioButton
        android:id="@+id/radioBtnThree"
        android:layout_width="fill_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:background="@drawable/custom_radiogroup_divider"
        android:text="Answer 3"/>
</RadioGroup>

現在、描画可能なフォルダー custom_radigroup_divider.xml にあります

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
       android:shape="rectangle" >

    <solid android:color="@android:color/transparent" />

    <stroke
       android:width="0.3dp"
       android:color="@android:color/black" />

</shape>

しかし、今問題は background プロパティを使用するときです

ラジオボタンは、テキストがラジオボタンに重なっているように見えます

4

3 に答える 3

5

Java コードからラジオボタンの背景を設定する必要があります。

radioBtnFirst.setButtonDrawable(R.drawable.custom_radiogroup_divider);

チェックボックスでも機能します;)

于 2013-08-21T08:05:36.193 に答える