2013-08-21 33 views
3

我得到了一些問題,同時改變單選按鈕的背景屬性改變單選按鈕的背景覆蓋文字上的單選按鈕的Android

所有我想每個單選按鈕其中有三個在一個單選框組

這裏是下面創建行的第一個下面的代碼

<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_radiogroup_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> 

,但現在的問題是,當我使用的背景屬性

的單選按鈕,看起來像文字重疊單選按鈕

回答

4

你必須設置從Java代碼的單選按鈕的背景:

radioBtnFirst.setButtonDrawable(R.drawable.custom_radiogroup_divider); 

它與複選框太;)

0

試試這個 放佈局寬度在radio_buttons佈局

2

待辦事項WRAP_CONTENT沒有設置爲背景,但將其設置爲按鈕。

使用此

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

做按鈕將刪除左電臺圖標方:( – Raksha

+0

@Raksha當你設置按鈕屬性意味着你正在自定義單選按鈕..爲此,你必須製作一個具有特定背景,你想要顯示的圖像,然後s等等。 –