Android的xml布局文件代码讲解(TextView控件)
以一个activity_main.xml为例
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
指定以下属性调用来自哪里
android:layout_width="match_parent"
指定布局的宽度
android:layout_height="match_parent"
指定布局的高度
tools:context=".MainActivity" >
指定布局所关联的Activity(可以不写)
<TextView
指定文本显示控件开始标签
android:id="@+id/main_hello"
指定控件的id(方便java编程时调用)
android:layout_width="wrap_content"
指定控件的宽度
android:layout_height="wrap_content"
指定控件的高度
android:layout_centerHorizontal="true"
指定控件相对于父布局横向居中显示
android:layout_centerVertical="true"
指定控件相对于父布局垂直居中显示
android:text="好吗?"
指定文本控件显示的文本
/>
</RelativeLayout>