使用相对布局完成在Android屏幕上,下,左,右,中间分别显示北,南,西,东,中布局效果;写出布局文件
时间: 2024-03-01 14:52:20 浏览: 56
以下是使用相对布局完成在Android屏幕上,下,左,右,中间分别显示北,南,西,东,中布局效果的布局文件:
```
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- 北 -->
<TextView
android:id="@+id/north_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="北"/>
<RelativeLayout
android:id="@+id/south_layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_alignParentBottom="true">
<!-- 南 -->
<TextView
android:id="@+id/south_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="南"/>
</RelativeLayout>
<RelativeLayout
android:id="@+id/west_layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_alignParentLeft="true">
<!-- 西 -->
<TextView
android:id="@+id/west_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="西"/>
</RelativeLayout>
<RelativeLayout
android:id="@+id/east_layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_alignParentRight="true">
<!-- 东 -->
<TextView
android:id="@+id/east_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="东"/>
</RelativeLayout>
<!-- 中 -->
<TextView
android:id="@+id/center_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="中"
android:layout_centerInParent="true"/>
</RelativeLayout>
```
在此布局中,我们使用了一个相对布局,并在其中添加了五个文本视图,分别用于显示北、南、西、东和中。我们使用了相对布局的属性来控制这些视图的位置,如`layout_centerHorizontal`、`layout_alignParentBottom`、`layout_alignParentRight`等。