写一个简单的线性布局
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Hello World!"
android:textSize="24sp"
android:gravity="center"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Click me!"
android:layout_gravity="center"/>
</LinearLayout>
这个布局文件包含一个垂直方向的线性布局,其中包含一个居中对齐的文本视图和一个居中对齐的按钮。可以将这个布局文件保存为一个名为 activity_main.xml
的文件,然后将它作为主活动的布局文件。