安卓学习-界面-布局-RelativeLayout

RelativeLayout相对布局,所有内部的组件都是相对的

XML属性

XML属性函数说明
android:gravitysetGravity内部组件的对其方式
android:ignoreGravitysetIgnoreGravity设置哪个组件不受Gravity影响

 

 

 

 

RelativeLayout.LayoutParams用来设置内部组件的对齐方式

XML属性说明
android:layout_centerHorizontal水平居中
android:layout_centerVertical垂直居中
android:layout_centerInParent水平垂直居中
android:layout_alignParentTop布局上、下、左、左、右
android:layout_alignParentBottom
android:layout_alignParentRight
android:layout_alignParentLeft
android:layout_toRightOf该组件位于指定ID的右侧
android:layout_toLeftOf该组件位于指定ID的左侧
android:layout_above该组件位于指定ID的上
android:layout_below该组件位于指定ID的下
android:layout_alignTop 
android:layout_alignLeft 
android:layout_alignRight 
android:layout_alignBottom 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

代码

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="${relativePackage}.${activityClass}" >

    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:text="水平居中" />
    
    <Button
        android:id="@+id/button2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerVertical="true"
        android:text="垂直居中" />
    
    <Button
        android:id="@+id/button3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:text="垂直水平居中" />
    
    <Button
        android:id="@+id/button4"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:text="布局顶端" />
    
    <Button
        android:id="@+id/button5"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentBottom="true"
        android:text="布局左边底部" />
    
    <Button
        android:id="@+id/button6"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:text="布局右边" />

    <Button
        android:id="@+id/button7"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentRight="true"
        android:text="布局右边底部" />
</RelativeLayout>
View Code

 

 梅花图形

 

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="${relativePackage}.${activityClass}" >

    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"

        android:src="@drawable/a12" />

    <ImageView
        android:id="@+id/imageView5"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/imageView1"
        android:layout_toRightOf="@+id/imageView3"
        android:src="@drawable/a12" />

    <ImageView
        android:id="@+id/imageView4"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_above="@+id/imageView5"
        android:layout_toRightOf="@+id/imageView1"
        android:src="@drawable/a12" />

    <ImageView
        android:id="@+id/imageView3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignTop="@+id/imageView1"
        android:layout_toLeftOf="@+id/imageView1"
        android:src="@drawable/a12" />

    <ImageView
        android:id="@+id/imageView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_above="@+id/imageView1"
        android:layout_alignLeft="@+id/imageView1"
        android:src="@drawable/a12" />
    
</RelativeLayout>
View Code

 

转载于:https://www.cnblogs.com/weijj/p/3925653.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值