一.RelativeLayout(相对布局)重点:
在没有指点位置的情况下,RelativeLayout会默认生成控件的位置是左上角
所以必须需要添加属性android:id="@+id/name"定义控件的名称,其他控件就可以通过@id/name找到它进行相对布局
二.RelativeLayout(相对布局)相关的属性:
<?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" >
<Button
android:id="@+id/cbut"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="中间"
/>
<Button
android:id="@+id/tbut"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_above="@id/cbut"
android:text="上面"
/>
<Button
android:id="@+id/tlbut"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_above="@id/cbut"
android:layout_toLeftOf="@id/tbut"
android:text="左上"
/>
<Button
android:id="@+id/trbut"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_above="@id/cbut"
android:layout_toRightOf="@id/tbut"
android:text="右上"
/>
<Button
android:id="@+id/bbut"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_below="@id/cbut"
android:text="下面"
/>
<Button
android:id="@+id/lbut"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_toLeftOf="@id/cbut"
android:text="左面"
/>
<Button
android:id="@+id/rbut"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_toRightOf="@id/cbut"
android:text="右面"
/>
<Button
android:id="@+id/blbut"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/bbut"
android:layout_alignLeft="@+id/lbut"
android:text="左下" />
<Button
android:id="@+id/brbut"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/bbut"
android:layout_alignLeft="@+id/rbut"
android:text="右下" />
</RelativeLayout>
运行结果如下:
以上就是我对RelativeLayout(相对布局)理解