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>
本文详细解析了Android中的XML布局文件,以activity_main.xml为例,讲解了如何使用RelativeLayout并配置TextView控件。重点阐述了android:layout_width、android:layout_height属性以及如何通过android:layout_centerHorizontal和android:layout_centerVertical实现控件的居中显示,并介绍了如何设置显示文本。

187

被折叠的 条评论
为什么被折叠?



