您的位置:首页 > 其它

五大布局——相对布局

2015-08-18 20:17 281 查看

1.RelativeLayout属性

1.alignParentLeft Right Bottom Top 相对父空间的上下左右

2.centerInParent centerVertical centerHorizontal

3.toLeftOf(R)=”@id/”……在 的左边 above below

4. alingleft(R,T,B)=”@id/”相对后边跟的ID的那个空间上下左右边对齐

5. layout_alignBaseline 基准线对齐

2.RelativeLayout布局的实现

alignParentLeft(R,B,T),centerInParent的实现



<?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:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="button1"
android:id="@+id/button"

android:layout_alignParentLeft="true"
android:background="@color/red"
></Button>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"

android:layout_alignParentBottom="true"
android:background="@color/red"></Button>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="@color/red"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:background="@color/red"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:background="@color/red"></Button>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:background="@color/red"/>

</RelativeLayout>


2.toLeftOf(R),layout_above,layou_below



<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="center"
android:id="@+id/button"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toLeftOf="@id/button"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/button"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@id/button"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/button"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/button"
android:layout_below="@id/button"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/button"
android:layout_above="@id/button"/>
</RelativeLayout>


3.alignLeft(R,T,B)



<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:layout_width="200dp"
android:layout_height="200dp"
android:layout_centerInParent="true"
android:id="@id/button"
android:background="@color/red"/>

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignRight="@id/button"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@id/button"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@id/button"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="@id/button"
android:layout_alignRight="@id/button"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@id/button"
android:layout_alignBottom="@id/button"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@id/button"/>
</RelativeLayout>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: