自定義RadioButton 文字在下,圖片在上

[html] view plaincopy
  1. <LinearLayout android:id="@+id/status_toolbar"  
  2.     android:layout_width="fill_parent"  
  3.     android:layout_height="wrap_content"  
  4.     android:layout_alignParentBottom="true"  
  5.     android:orientation="horizontal"  
  6.     android:background="@drawable/status_toolbar_bg"  
  7.     android:gravity="center_vertical|center_horizontal"  
  8.     >  
  9.   
  10.     <RadioButton  
  11.         android:background="@android:color/transparent"  
  12.         android:layout_width="wrap_content"  
  13.         android:layout_height="wrap_content"  
  14.         android:button="@null"  
  15.         android:drawableTop="@drawable/status_refresh_selector"  
  16.         android:gravity="center"  
  17.         android:text="刷新"  
  18.         android:layout_weight="1"  
  19.         android:textColor="@color/white" />  
  20.   
  21.        
  22.        <RadioButton android:layout_width="wrap_content"  
  23.         android:layout_height="wrap_content"  
  24.         android:button="@null"  
  25.         android:text="評論"  
  26.         android:gravity="center"  
  27.         android:layout_weight="1"  
  28.        android:background="@android:color/transparent"  
  29.         android:textColor="@color/white"  
  30.         android:drawableTop="@drawable/status_comment_selector"></RadioButton>  
  31.        
  32.        <RadioButton android:layout_width="wrap_content"  
  33.         android:layout_height="wrap_content"  
  34.         android:button="@null"  
  35.         android:text="轉發"  
  36.         android:gravity="center"  
  37.         android:layout_weight="1"  
  38.         android:background="@android:color/transparent"  
  39.         android:textColor="@color/white"  
  40.         android:drawableTop="@drawable/status_forward_selector"></RadioButton>  
  41.        
  42.        <RadioButton android:layout_width="wrap_content"  
  43.         android:layout_height="wrap_content"  
  44.         android:button="@null"  
  45.         android:text="收藏"  
  46.         android:gravity="center"  
  47.         android:layout_weight="1"  
  48.         android:background="@android:color/transparent"  
  49.         android:textColor="@color/white"  
  50.         android:drawableTop="@drawable/status_fav_selector"></RadioButton>  
  51.       
  52.        <RadioButton android:layout_width="wrap_content"  
  53.         android:layout_height="wrap_content"  
  54.         android:button="@null"  
  55.         android:text="更多"  
  56.         android:gravity="center"  
  57.         android:layout_weight="1"  
  58.         android:background="@android:color/transparent"  
  59.         android:textColor="@color/white"  
  60.         android:drawableTop="@drawable/status_more_selector"></RadioButton>  
  61.       </LinearLayout>  


關鍵語句功能:

android:button="@null" 刪除原本系統默認在左的選擇框

android:background="@android:color/transparent"  去除左邊選擇框被刪除後的空白

android:drawableTop="@drawable/status_more_selector" 選擇圖片在文字上面

android:gravity="center" 保證文字與圖片在平行

android:layout_weight="1" 使每一個RadioButton佔的空間一樣大

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章