五大布局——相对布局

来源:互联网 发布:软件求职自我介绍 编辑:程序博客网 时间:2024/05/29 11:10

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>
0 0
原创粉丝点击