1.TextView
<TextView
android:id="@+id/text_view"
android:layout_width="match_parent"
android:Layout_height="wrap_content"
android:text="This is TextView"/>
android:id给当前控件指定唯一的标识符
android:layout_width和android:Layout_height指定控件的宽度和高度,Android所有的控件都有这两个属性,可选的值有三种:match_parent fill_parent和wrap_content,其中match_parent 和fill_parent的意义相同,推荐使用match_parent 表示让当前的控件的大小和父布局的大小一样,也就是由父布局来决定当前控件的大小,wrap_content表示让当前控件的大小能够刚好包含住里面的内容,也就是由控件内容决定当前控件的大小,也可以对控件的宽高指定一个固定的大小,但是这样做在不同屏幕大小的手机上出现适配问题
android:text指定TextView中的文本显示内容
android:gravity指定文字的对齐方式,可选值为top bottom left right center 等,也可用 | 来指定多个值.center效果等同于 center_vertical | center_horizontal,表示文字在垂直和水平方向都居中对齐
android:textSize 指定文字大小
android:textColor 指定文字颜色
2.Button
<Button
android:id="@+id/button"
android:layout_width="match_parent"
android:Layout_height="wrap_content"
android:text="Button"
android:textAllCaps="false"/>
android:textAllCaps 由于系统会对Button的所有英文字母进行大写转换,该属性设为false就不转换了
3.EditText
<EditText
android:id="@+id/edit_text"
android:layout_width="match_parent"
android:Layout_height="wrap_content"
android:hint="Type something here"
android:maxLines="2"/>
android:hint 属性指定了一段提示文本,当我们输入任何内容,这段文本就会自动消失
android:maxLines 属性指定了EditText最大行数为2行,这样当输入的内容超过两行时,文本就会向上滚动,而EditText不会再继续拉伸.
4.ImageView
<ImageView
android:id="@+id/image_view"
android:layout_width="match_parent"
android:Layout_height="wrap_content"
android:src="@drawable/img"/>
android:src 该属性给ImageView指定一张图片,
通过代码指定图片
private ImageView imageView;
imageView = (ImageView)findViewById(R.id.image_view);
imageView.setImageResource(R.drawable.img);
5.ProgressBar
在用户界面显示一个进度条
<ProgressBar
android:id="@+id/progress_bar"
android:layout_width="match_parent"
android:Layout_height="wrap_content"
style="?android:attr/progressBarStyleHorizontal"
android:max="100"/>
style属性可以设置进度条样式
android:max属性设置进度条最大值