安卓常见布局,左上角右上角和下方一排。
效果:
代码(可能有赘余不足):
<?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"
android:orientation="horizontal">
<LinearLayout
android:id="@+id/f1_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<LinearLayout
android:id="@+id/f2_container"
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:gravity = "left">
<Button
android:id="@+id/button_1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="按钮1"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<Button
android:id="@+id/button_2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="按钮2"
android:layout_below="@+id/button_1"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
</LinearLayout>
<LinearLayout
android:id="@+id/f3_container"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:id="@+id/button_3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="按钮3"
android:layout_gravity= "top|right"
android:layout_alignParentRight="true"/>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:id="@+id/f4_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity = "center|bottom"
xmlns:android="http://schemas.android.com/apk/res/android">
<Button
android:id="@+id/button_M"
android:layout_width="wrap_content"
android:layout_height="60dp"
android:text="功能1"
android:layout_weight="1"/>
<Button
android:id="@+id/button_S"
android:layout_width="wrap_content"
android:layout_height="80dp"
android:text="功能2"
android:layout_weight="1"/>
<Button
android:id="@+id/button_G"
android:layout_width="wrap_content"
android:layout_height="60dp"
android:text="功能3"
android:layout_weight="1"/>
</LinearLayout>
</RelativeLayout>
让我头秃一个小时的 cannot resolve symbol ‘R’ 的原因是RelativeLayout里android:orientation=“horizontal” 一开始写的是vertical,xml下面应该是一直有报错信息但我没注意。所以新建文件就全红了,真是 折寿啊/滑稽脸。为什么不是vertical我也不知道/滑稽脸