Android常用控件

Android常用控件

Android常用控件分为四类

文本类控件
TextView 负责展示文本,非编辑
EditText 可编辑文本控件
按钮类控件
Button 按钮
ImageButton 图片按钮
RadioButton与RadioGroup 单选按钮
CheckBox 复选按钮
图片控件
ImageView 负责显示图片
进度条控件
ProgressBar 进度条

文本类控件

TextView可以说是Android中最简单的控件,主要用于在界面上显示一段文本信息,例:

<LinearLayout
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
        <TextView
            android:id="@+id/text_view"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:text="这是TextView"/>

    </LinearLayout>

运行结果:
这里写图片描述

EditText是程序用于和用户进行交互的一个重要控件,它允许用户在控件里输入和编辑内容,并可以在程序中对这些内容进行处理,如下:

<LinearLayout
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
        ......
        <EditText
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            />
    </LinearLayout>

运行后输入文本信息:
这里写图片描述

按钮类控件

Button是程序用于和用户进行交互的另一个重要控件,它的配置属性和TextView差不多

<LinearLayout
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
        ......
        <Button
       android:id="@+id/btn1"
       android:layout_width="match_parent"
       android:layout_height="wrap_content"
       android:text="这是Button"/>
    </LinearLayout>

运行结果:
这里写图片描述

ImageButton和Button类似,是一个按钮,ImageButton可以实现我们任何想要的图片按钮的效果,比如我们租一个下载的按钮等等:

<LinearLayout
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
        ......
        <ImageButton
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:scaleType="fitXY"
            android:src="@drawable/add"/>
    </LinearLayout>

如上,给ImageButton用android:src添加了一张图片,结果如下:
这里写图片描述

RadioButton(单选按钮)在 Android 平台上也比较常用,比如一些选择项会用到单选按钮。它是一种单个圆形单选框双状态的按钮,可以选择或不选择。在 RadioButton 没有 被选中时,用户通过单击来选中它。

<LinearLayout
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
        ......
        <RadioButton
            android:id="@+id/rd2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textSize="30sp"
            android:text="单选按钮" />
    </LinearLayout>

结果:
这里写图片描述

CheckBox(复选按钮),顾名思义是一种可以进行多选的按钮,默认以矩形表示。与 RadioButton 相同,它也有选中或者不选中双状态。

<LinearLayout
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
        ......
        <CheckBox
            android:id="@+id/cb1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="北京"
            android:textSize="30sp" />
        <CheckBox
            android:id="@+id/cb2"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="上海"
            android:textSize="30sp" />
    </LinearLayout>

这里写图片描述

ImageView 是一个图片控件,负责显示图片,图片的来源可以是系统提供的资源文件,也可以是 Drawable 对象。

<LinearLayout
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
        ......
        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id = "@+id/xxx"
            android:scaleType="fitXY"
            android:src ="@drawable/ic_launcher_background"/>
    </LinearLayout>

如上,添加了系统的ic_launcher_background图片:
这里写图片描述

ProgressBar 用于在界面上显示一个进度条,表示我们的程序正在加载一些数据,运行程序,会看到屏幕中有一个圆形进度条正在旋转。

<LinearLayout
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
        ......
        <ProgressBar
            android:id="@+id/pb"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            />
    </LinearLayout>

这里写图片描述

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值