http://gundumw100.iteye.com/blog/1146527
How does the effect of the above 3-choice 1 work? Write in code?
In fact, there is a more simple way to forget the RadioButton have any characteristics?
I used RadioButton to achieve the above effect, in fact, very simple.
First define a background, named Radio.xml, and note that the background must be an XML-styled picture:
XML code
<?XML version= "1.0" encoding= "Utf-8"?> <selectorxmlns:android= "Http://schemas.android.com/apk/res/android"> <Itemandroid:state_checked= "false"android:drawable= "@drawable/tabswitcher_long" /> <Itemandroid:state_checked= "true"android:drawable= "@drawable/tabswitcher_short" /> </selector>
Here we can only care about the state_checked state. So it's very simple to configure.
The next step is to refer to this image in the layout file:
Layout file
<Radiogroup android:gravity= "Center"android:orientation= "Horizontal"Android:layout_width= "Fill_parent"Android:layout_height= "Wrap_content" > <RadioButton Android:id= "@+id/btn_0"Android:layout_width= "Fill_parent"Android:layout_height= "Wrap_content"Android:text= "Latest Information"android:textsize= "17.0SP"Android:textcolor= "@android: Color/black"android:gravity= "Center"Android:layout_weight= "1"android:checked= "true"Android:button= "@null"Android:background= "@drawable/radio"/> <RadioButton Android:id= "@+id/btn_1"Android:layout_width= "Fill_parent"Android:layout_height= "Wrap_content"Android:text= "Online Expert"android:textsize= "17.0SP"Android:textcolor= "@android: Color/black"android:gravity= "Center"Android:layout_weight= "1"Android:button= "@null"Android:background= "@drawable/radio"/> <RadioButton Android:id= "@+id/btn_2"Android:layout_width= "Fill_parent"Android:layout_height= "Wrap_content"Android:text= "Reservation Service"android:textsize= "17.0SP"Android:textcolor= "@android: Color/black"android:gravity= "Center"Android:layout_weight= "1"Android:button= "@null"Android:background= "@drawable/radio"/> </RadioGroup>
Note android:button= "@null" is all set to NULL, and android:background= "@drawable/radio" is set to the picture you just created. So it's done.
You don't have to write a single line of code!
Look at the effect of the vertical:
What if there are icons on the side?
Also very simple, as long as in each RadioButton add android:drawableleft= "@drawable/tubiao_0" on it.
Also to set the distance between the icon and the text?
There is a way setcompounddrawablepadding (PAD) can set the distance between the icon and the text, the corresponding property is android:drawablepadding.
With this trick can be achieved similar to the N 1 effect, see below:
Application:
http://www.iteye.com/topic/1116261#2256664