RelativeLayout布局

来源:互联网 发布:js点击li添加样式 编辑:程序博客网 时间:2024/04/28 11:42

RelativeLayout布局

RelativeLayout布局

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:layout_width="match_parent"    android:layout_height="match_parent">    <Button        android:id="@+id/center"        android:layout_width="150dp"        android:layout_height="wrap_content"        android:text="中间"        android:textSize="32dp"        android:layout_centerInParent="true"/>    <!--         android:layout_alignLeft="@id/center"         android:layout_alignRight="@id/center"         使用layout_alignLeft和layout_alignRight会拉伸控件使空间对齐         gravity对齐方式    -->    <Button        android:gravity="center"        android:layout_alignLeft="@id/center"        android:layout_alignRight="@id/center"        android:layout_above="@id/center"        android:layout_centerHorizontal="true"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:text="上面"        android:textSize="32dp"/>    <Button        android:layout_alignLeft="@id/center"        android:layout_alignRight="@id/center"        android:layout_below="@id/center"        android:layout_centerHorizontal="true"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:text="下面"        android:textSize="32dp"/>    <!--        只要一边用了layout_toLeftOf,就可以使用android:layout_width="match_parent"    -->    <Button        android:layout_toLeftOf="@id/center"        android:layout_above="@id/center"        android:layout_width="match_parent"        android:layout_height="wrap_content"        android:text="左上"        android:textSize="32dp"/>    <Button        android:layout_toLeftOf="@id/center"        android:layout_below="@id/center"        android:layout_width="match_parent"        android:layout_height="wrap_content"        android:text="左下"        android:textSize="32dp"/>    <Button        android:layout_toRightOf="@id/center"        android:layout_above="@id/center"        android:layout_width="match_parent"        android:layout_height="wrap_content"        android:text="右上"        android:textSize="32dp"/>    <Button        android:layout_toRightOf="@id/center"        android:layout_below="@id/center"        android:layout_width="match_parent"        android:layout_height="wrap_content"        android:text="右下"        android:textSize="32dp"/>    <Button        android:layout_alignTop="@id/center"        android:layout_toLeftOf="@+id/center"        android:layout_width="match_parent"        android:layout_height="wrap_content"        android:text="左边"        android:textSize="32dp"/>    <Button        android:layout_alignTop="@id/center"        android:layout_toRightOf="@+id/center"        android:layout_width="match_parent"        android:layout_height="wrap_content"        android:text="右边"        android:textSize="32dp"/></RelativeLayout>
0 0
原创粉丝点击