Android学习(五):常用控件

Android学习(五):常用控件

常用控件

  • TextView
  • EditText
  • Button
  • RadioButton
  • ImageView

1、TextView控件

1.1、简介

TextView是用于显示文字(字符串)的控件,可在代码中通过设置属性改变文字的大小、颜色、样式等功能。

1.2、示例
<TextView
	android:layout_width="wrap_content"
	android:layout_height="wrap_content"
	android:text="@string/hello_android"
	app:layout_constraintBottom_toBottomOf="parent"
	app:layout_constraintLeft_toLeftOf="parent"
	app:layout_constraintRight_toRightOf="parent"
	app:layout_constraintTop_toTopOf="parent" />

2、EditText控件

2.1、简介

EditText继承自TextView,可以进行编辑操作,将用户信息传递给Android程序。还可以为EditText控件设置监听器,用来测试用户输入的内容是否合法。

2.2、示例
<EditText
	android:id="@+id/editText"
	android:layout_width="wrap_content"
	android:layout_height="wrap_content"
	android:ems="10"
	android:inputType="textPassword"
	tools:layout_editor_absoluteX="64dp"
	tools:layout_editor_absoluteY="179dp"
	tools:ignore="LabelFor,MissingConstraints"
	android:autofillHints="11" />

3、Button控件

3.1、简介

Button是按钮,是用于响应用户的一系列点击事件,使程序更加流畅和完整。

3.2、示例
<Button
	android:id="@+id/button"
	android:layout_width="wrap_content"
	android:layout_height="wrap_content"
	android:text="Button"
	tools:layout_editor_absoluteX="133dp"
	tools:layout_editor_absoluteY="431dp"
	tools:ignore="MissingConstraints" />

4、RadioButton控件

4.1、简介
  • RadioButton为单选按钮,它需要与RadioGroup配合使用,提供两个或多个互斥的选项集。
  • RadioGroup是单选组合框,可容纳多个RadioButton,并把它们组合在一起,实现单选状态。
4.2、示例
<RadioButton
	android:id="@+id/radioButton"
	android:layout_width="wrap_content"
	android:layout_height="wrap_content"
	android:text="RadioButton"
	tools:layout_editor_absoluteX="116dp"
	tools:layout_editor_absoluteY="512dp"
	tools:ignore="MissingConstraints" />

5、ImageView控件

5.1、简介

ImageView是视图控件,它继承自View,其功能是在屏幕中显示图像。ImageView类可以从各种来源加载图像(如资源库或网络),并提供缩放、裁剪、着色(渲染)等功能。

5.2、示例
<ImageView
	android:id="@+id/imageView"
	android:layout_width="wrap_content"
	android:layout_height="wrap_content"
	app:srcCompat="@drawable/ic_launcher_background"
	tools:layout_editor_absoluteX="130dp"
	tools:layout_editor_absoluteY="112dp"
	tools:ignore="MissingConstraints,VectorDrawableCompat"
	android:contentDescription="@string/todo" />
  • 10
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值