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:常见简易消息提示框

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值