Radiobutton也來做tab標籤

來源:互聯網
上載者:User

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屬性

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.