activity-main.xml里面应该怎么写
时间: 2024-02-06 14:10:49 浏览: 30
activity-main.xml是Android应用程序中的一个布局文件,用于定义应用程序的主界面。你可以根据自己的需要来编写该文件,以下是一个示例代码:
```xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!" />
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/textView"
android:text="Click me" />
</RelativeLayout>
```
这个布局文件使用RelativeLayout来定义界面的布局,包含一个TextView和一个Button控件。TextView用于显示文本,Button用于触发点击事件。你可以根据自己的需要修改或添加控件,以实现你的应用程序功能。