1.定義drawable樣式
drawable/style_button_subject.xml如下:
<?xml version="1.0" encoding="utf-8"?>
<selector
xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_checked="false" android:drawable="@drawable/buttonsubject_1"/>
<item android:state_checked="true" android:drawable="@drawable/buttonsubject_2"/>
<item android:state_selected="true" android:drawable="@drawable/buttonsubject_2"/>
<item android:state_pressed="true" android:drawable="@drawable/buttonsubject_2"/>
</selector>
2.為RadioButton設置drawable樣式
<RadioButton
android:id="@+id/buttonsubject11"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="85"
android:button="@null"
android:gravity="center"
android:textSize="@dimen/buttonSubjectTextSize"
android:background="@drawable/style_button_subject"
/>
這樣就得到了可以拉伸的圖片作為背景的RatioButton
注意要設置android:button="@null",否則還是會有一個可以選擇的圈圈出現