1. 程式人生 > 實用技巧 >291 選餐案例-基礎控制元件之2-RadioButton

291 選餐案例-基礎控制元件之2-RadioButton

291 選餐案例-基礎控制元件之2-RadioButton

說明:因為時間緊張,本人很多部落格的寫作過程中只是對知識點的關鍵步驟進行了截圖記錄,沒有對截圖步驟進行詳細的文字說明(後面博主時間充裕了,會對目前的部落格編輯修改,補充上詳細的文字說明);有些步驟和相關知識點缺乏文字描述,可能會難以理解。讀者如有不明之處,歡迎部落格私信或者微信(本人微信在部落格下方的“關於博主”處)與本人交流,共同進步

另有一些部落格沒有來得及記錄內容,但為了保證部落格內容的連貫性,所以按照學習路徑的順序先發布了標題,後續時間充裕了會更新內容,望博友和讀者朋友們諒解!

RadioButton和CheckBox的區別:

效果:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <CheckBox
        android:id="@+id/checkBox"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:checked="true"
        android:text="CheckBox" />

    <RadioGroup
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >

        <RadioButton
            android:id="@+id/radiobutton2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="RadioButton" />

        <RadioButton
            android:id="@+id/radiobutton3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="RadioButton" />

        <RadioButton
            android:id="@+id/radiobutton"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="RadioButton" />
    </RadioGroup>
</LinearLayout>