Android开发总结笔记 RelativeLayout(相对布局) 1-1-2

来源:互联网 发布:淘宝口令转换 编辑:程序博客网 时间:2024/04/29 18:06
RelativeLayout的继承结构


相对布局,顾名思义就是相对于某个组件而摆放的位置。所以,相对布局的常用属性都与这个“相对”有关(RelativeLayout API)


下面演示这几个常用属性的方法

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center">
 
<ImageView
android:id="@+id/android"
android:layout_centerInParent="true"
android:background="@mipmap/ic_launcher"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<!-在android的左边-> 
<ImageView
android:layout_centerVertical="true"
android:layout_toLeftOf="@id/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@mipmap/ic_launcher" />
<!-在android的右边-> 
<ImageView
android:layout_centerVertical="true"
android:layout_toRightOf="@id/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@mipmap/ic_launcher" />
<!-在android的上边-> 
<ImageView
android:layout_centerHorizontal="true"
android:layout_above="@id/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@mipmap/ic_launcher" />
<!-在android的下边-> 
<ImageView
android:layout_centerHorizontal="true"
android:layout_below="@id/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@mipmap/ic_launcher" />
</RelativeLayout>
效果图


<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center">
 
<ImageView
android:layout_centerInParent="true"
android:background="@mipmap/ic_launcher"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
 
<ImageView
android:layout_alignParentLeft="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@mipmap/ic_launcher" />
 
<ImageView
android:layout_alignParentRight="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@mipmap/ic_launcher" />
 
<ImageView
android:layout_alignParentTop="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@mipmap/ic_launcher" />
 
<ImageView
android:layout_alignParentBottom="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@mipmap/ic_launcher" />
</RelativeLayout>


效果图



0 0