zoukankan      html  css  js  c++  java
  • Android学习之路三:CheckBox和RadioButton

      CheckBox(复选框)和RadioButton(单选框)正好是截然相反的两种按钮。

      CheckBox(复选框)案例:

      XML代码(1.java代码可以不用管,2.要用LinearLayout的vertical,否则选项会重合):

    <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" >
    
        <CheckBox
            android:id="@+id/chk1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/choice1"/>
        <CheckBox
            android:id="@+id/chk2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/choice2"/>
        <CheckBox
            android:id="@+id/chk3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/choice3"/>
    </LinearLayout>

      RadioButton(单选框)案例:

      XML代码(1.可以不要java代码即可展示,2.要用RelateveLayout,如果用LinearLayout会出现警告:"This RadioGroup layout or its LinearLayout parent is useless"):

    <RelateveLayout 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" >
    
        <RadioGroup
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:checkedButton="@+id/radioGroupValue">
            <RadioButton
                android:id="@+id/chk1"
                android:text="@string/choice1"/>
            <RadioButton
                android:id="@+id/chk2"
                android:text="@string/choice2"/>
            <RadioButton
                android:id="@+id/chk3"
                android:text="@string/choice3"/>
        </RadioGroup>
    </RelateveLayout>
  • 相关阅读:
    D触发器的使用小结
    CAN通信帧ID的含义解析? (转载)
    mcp2515屏蔽寄存器和过滤寄存器的学习
    spi调试步骤,mcp2515调试整理
    最近工作小结2019.11.24
    Can总线上的电平及物理层仲裁
    can总线学习网上资料汇总
    can总线的远程帧(遥控帧)—说的很形象
    在IAR平台建立STC8ASK64S4A12单片机工程
    cortex-m系列的区别(图解)及今日碎片学习笔记
  • 原文地址:https://www.cnblogs.com/thinksasa/p/2918642.html
Copyright © 2011-2022 走看看