Android的常用控件

各大控件的使用

android的八大控件分别是text View,edittext,button,checkbox,radio button,image view,image button,dialog

TextView:文本框,用于显示不可编辑的文本信息

<TextView
    android:text="微信"
    android:textSize="20dp"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" />

其中的text属性:表示文本的内容
textsize属性:字体内容的大小
layout_width:文本的宽度,wrap_content则是自适应宽度,内容有多少所占用的宽度也是多少
layout_height:文本的长度

EditText:编辑框,可以编辑内容的文本框

<EditText
    android:layout_width="200dp"
    android:layout_height="wrap_content" 
    android:textSize="20dp"/>

Button:按钮,可以响应用户点击事件的控件

 <Button
        android:layout_below="@id/et"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:onClick="show"
        android:text="提交"/>

onClick属性:单击事件,提供一个自己定义的单击事件方法

CheckBox:复选框

 <CheckBox
       android:id="@+id/cb1"
       android:layout_width="wrap_content"
       android:layout_height="wrap_content" 
       android:layout_below="@id/bt1"
       android:text="唱歌"/>
    <CheckBox
        android:layout_toRightOf="@id/cb1"
        android:id="@+id/cb2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/bt1"
        android:text="跳舞"/>
    <CheckBox
        android:layout_toRightOf="@id/cb2"
        android:id="@+id/cb3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/bt1"
        android:text="看书"/>
    <CheckBox
        android:layout_toRightOf="@id/cb3"
        android:id="@+id/cb4"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/bt1"
        android:text="吃零食"/>

RadioButton/RadioGroup:单选按钮

<RadioGroup
        android:orientation="horizontal"
        android:layout_below="@id/cb4"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content">
    <RadioButton
        android:id="@+id/rb1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
       android:text="男"

        />
    <RadioButton
        android:id="@+id/rb2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="女"
        />

ImageView:图片控件、用于显示图片

 <ImageView
        android:layout_width="500px"
        android:layout_height="500px"
        android:src="@mipmap/longmao"
        android:id="@+id/img"/>

ImageButton:图片按钮,可以设置图片信息的按钮

<ImageButton
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:layout_below="@id/rg"
        android:src="@mipmap/ic_launcher"/>

src属性:选择图片的位置,调用图片

Dialog:常见简易消息提示框

猜你喜欢

转载自blog.csdn.net/xxz2645746142/article/details/80568180