<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
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:textSize="24sp"
android:textColor="#00ff00"
android:text="This is TextView" />
</LinearLayout>
1.
android:id属性,给当前的控件定义一个唯一的标识符。
2.
(1) android:layout_width属性,指定当前元素的宽度
(2) android:layout_height属性,指定当前元素的高度
(2.1) 以上两个属性,可以选择以下3种值:
(2.1.1) match_parent和fill_parent,表示让当前控件的大小和父元布局的大小一样,也就是有父布局决定当前控件的大小。官方推荐使用match_parent。
(2.1.2) wrap_content,表示让当前控件的大小能够刚好包含住里面的内容,也就是由控件内容决定当前控件的大小。
3.
android:text属性,指定控件中显示的文本内容
4.
android:gravity属性,指定文字的对齐方式
(4.1) 可选值
5.
android:textSize属性,指定文字的大小。在Android中字体大小使用sp作为单位。
6.
android:textColor属性,指定文字的颜色。