Android進階之UI深度定制系列(二)
Radiobutton也來做tab標簽
效果圖:

XML布局:
<RadioGroup android:id="@+id/radioGroup1" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal" > <RadioButton android:id="@+id/radio0" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_weight="1" android:background="@drawable/XXX" android:button="@drawable/none" android:checked="true" android:drawableTop="@drawable/yyy" android:text="RadioButton" /> <RadioButton android:id="@+id/radio1" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_weight="1" android:background="@drawable/xxx" android:button="@drawable/none" android:drawableTop="@drawable/yyy" android:text="RadioButton" /> <RadioButton android:id="@+id/radio2" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_weight="1" android:background="@drawable/xxx" android:button="@drawable/none" android:drawableTop="@drawable/yyy" android:text="RadioButton" /> </RadioGroup>
重要屬性:
android:drawableTop,android:button,android:background
隨着ADT不斷升級,可視化的UI編輯變得更加方便高效,通過Properties面板,能夠快捷的查詢設置UI組件各種屬性,
理解RadioButton是實現個性化定制前提,android:drawableTop表示組件內相對上方的圖片資源,默認是沒有的;android:button表示我們平時看到的圓圈Radio,是一個drawable資源而不是按鈕id;android:background當然表示整個RadioBtton的背景圖片。
為了時三個RadioButton能夠均勻占據屏幕的寬,設置layout_width為match_parent,同時設置他們的layout_weight為一,即在分配寬度時得到相同的優先級。
優勢:
保持選中狀態,實現不同視覺效果,而通常的做法只能在單擊或觸摸時有效果的變化,而本例將實現這種效果的固化,就是利用了RadioButton的checked屬性
