帮我写一个包含线性布局,相对布局,表格布局的AS代码
时间: 2023-05-24 22:04:55 浏览: 88
下面是一个简单的AS代码,其中包含线性布局(LinearLayout)、相对布局(RelativeLayout)和表格布局(TableLayout)。
```
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- 使用线性布局 -->
<TextView
android:text="Linear Layout Example:"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<Button
android:text="Button 1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<Button
android:text="Button 2"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<Button
android:text="Button 3"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
<!-- 使用相对布局 -->
<TextView
android:text="Relative Layout Example:"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<Button
android:id="@+id/button1"
android:text="Button 1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<Button
android:id="@+id/button2"
android:text="Button 2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/button1" />
<Button
android:id="@+id/button3"
android:text="Button 3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/button2" />
</RelativeLayout>
<!-- 使用表格布局 -->
<TextView
android:text="Table Layout Example:"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<TableLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TableRow>
<TextView
android:text="Name"
android:padding="5dp" />
<TextView
android:text="Age"
android:padding="5dp" />
<TextView
android:text="Gender"
android:padding="5dp" />
</TableRow>
<TableRow>
<TextView
android:text="John"
android:padding="5dp" />
<TextView
android:text="25"
android:padding="5dp" />
<TextView
android:text="Male"
android:padding="5dp" />
</TableRow>
<TableRow>
<TextView
android:text="Jane"
android:padding="5dp" />
<TextView
android:text="32"
android:padding="5dp" />
<TextView
android:text="Female"
android:padding="5dp" />
</TableRow>
</TableLayout>
</LinearLayout>
```
这个代码可以在布局中使用不同类型的布局,展示出不同的效果。你可以在自己的代码中加以修改和扩展,实现更多复杂的布局。