1.需求是这样的:
选一个宝宝,实现思想是RadioButton单选,
<RadioGroup android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentRight="true" android:layout_centerVertical="true" android:orientation="horizontal"> <RadioButton android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginRight="20dp" android:button="@null" android:checked="true" android:drawableLeft="@drawable/radio_button_sexchoice" android:drawablePadding="5dp" android:gravity="center_vertical" android:text="男宝宝" android:textColor="@drawable/radio_button_sexchoice_textcolor" /> <RadioButton android:layout_width="wrap_content" android:layout_height="wrap_content" android:button="@null" android:drawableLeft="@drawable/radio_button_sexchoice_woman" android:drawablePadding="5dp" android:text="女宝宝" android:textColor="@drawable/radio_button_sexchoice_textcolor" /> </RadioGroup>好,默认第一个,开心的变异运行,恩,不错,可以,选下女宝宝,恩???什么鬼?都选中了?不信自己试试!
说好的单选呢?亲?去哪了?看起来一点错误都没有。
难道是drawable写错了?
<selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:drawable="@drawable/zc_man_hover" android:state_checked="true" /> <item android:drawable="@drawable/zc_man" android:state_checked="false" />
<selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:color="@color/orange" android:state_checked="true" /> <item android:color="@color/gray" android:state_checked="false" />
<selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:drawable="@drawable/zc_woman_hover" android:state_checked="true" /> <item android:drawable="@drawable/zc_woman" android:state_checked="false" />
<selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:color="@color/orange" android:state_checked="true" /> <item android:color="@color/gray" android:state_checked="false" />包大人,我冤枉啊! 我没有写错啊!(你全家都写错!我才没写错)
那么,怎么办?
重启。还不行?换台电脑吧这台电脑坏了。法克
找了下属性,再看看写的
<RadioGroup android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentRight="true" android:layout_centerVertical="true" android:orientation="horizontal"> <RadioButton android:id="@+id/choice_boy" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginRight="20dp" android:button="@null" android:checked="true" android:drawableLeft="@drawable/radio_button_sexchoice" android:drawablePadding="5dp" android:gravity="center_vertical" android:text="男宝宝" android:textColor="@drawable/radio_button_sexchoice_textcolor" /> <RadioButton android:id="@+id/choice_girl" android:layout_width="wrap_content" android:layout_height="wrap_content" android:button="@null" android:drawableLeft="@drawable/radio_button_sexchoice_woman" android:drawablePadding="5dp" android:text="女宝宝" android:textColor="@drawable/radio_button_sexchoice_textcolor" /> </RadioGroup>妈蛋,没有变化啊,还是一样的啊,再看!多了什么?id!哦买噶,不申明id,会导致Radiobutton不互斥!
再见,这个世界!