编写一个APP布局文件
时间: 2023-09-03 15:05:52 浏览: 40
以下是一个简单的APP布局文件,包含一个顶部工具栏、一个标题、一张图片和一个按钮:
```xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="@color/colorPrimary"
android:title="My App" />
<TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/toolbar"
android:text="Welcome to My App"
android:textSize="24sp" />
<ImageView
android:id="@+id/image"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/title"
android:src="@drawable/my_image" />
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/image"
android:text="Click Me!" />
</RelativeLayout>
```
这个布局文件使用了RelativeLayout作为根视图,包含了一个顶部工具栏、一个标题、一张图片和一个按钮。工具栏使用了AndroidX库中的Toolbar,标题和按钮使用了TextView和Button控件,图片则使用了ImageView控件。每个控件都有一个唯一的ID,以便在代码中引用它们。