本章主要介绍安卓日常开发时主要使用的控件
-
TextView
用来显示字符串的控件,常用属性:
1、 android:text=“Hello World!” 设置内容
2、 android:textColor="@color/colorAccent" 设置文字的颜色
3、 android:textSize=“20sp” 设置字体大小
4、 android:layout_height=“wrap_content” 设置高度
5、 android:layout_width=“wrap_content” 设置宽度
6、 android:gravity=“center_horizontal” 设置文字相对于文本框的位置
7、 android:drawableLeft="@drawable/ic_launcher_background" 用于在文本框左侧绘制图片
8、 android:hint=“123” 设置默认显示字体
9、 android:ellipsize=“end” 设置当文字过长时结尾用省略号。
10、android:maxLength=“50” 限制文本 的长度,超出部分将会不显示
11、android:maxLines=“3” 最多几行 -
Imageview
用来显示图片,主要属性
1、android:background="@drawable/ic_launcher_background" 设置显示什么图片
2、android:scaleType=“centerCrop” 设置图片显示方法 -
Button
点击控件 -
EditText
输入框,主要属性
1、android:inputType=“number” 设置只能输入数字
2、android:hint=“用户名” 设置默认显示 -
Listview
垂直滚动list -
Gridview
宫格显示 -
RecycleView
更强大的view,集成listview和gridview功能,还可以瀑布流显示 -
webview
网页控件