Android移动开发--相对布局

1.第一组属性:android:layout_below,layout_above,layout_toLeftOf,layout_toRightOf\

第二组属性:android:layout_alignLeft,right,top,bottom(对齐)

2.对齐至控件的基准线

android:layout_alignBaseline

144828_BLld_2861931.png

145009_6yXJ_2861931.png

 

3.与父控件的四个边缘对齐,对齐父控件中央

android:layout_alignParentLeft,right,top,bottom(对齐)

145306_OaoW_2861931.png

android:layout_centerInParent,Horizontal,Vertical

145408_Prww_2861931.png145449_plqC_2861931.png145428_Uh6z_2861931.png

4.android4.2新属性

android:layout_alignStart,End,ParentStart,End

145809_ygRq_2861931.png145749_9h0J_2861931.png

5.例子:登录界面

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:padding="40dp"
    android:layout_width="match_parent"
    android:layout_height="match_parent">


    <EditText
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/editText"
        android:hint="username"
        android:layout_alignParentLeft="true"
        android:layout_alignParentRight="true"
        android:layout_below="@+id/textView" />

    <EditText
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/editText2"
        android:hint="password"
        android:layout_alignLeft="@id/editText"
        android:layout_alignRight="@id/editText"
        android:layout_below="@+id/editText" />

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/textView"
        android:gravity="center"
        android:textSize="20sp"
        android:text="登陆界面"/>

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="取消"
        android:id="@+id/button"
        android:layout_below="@+id/editText2"
        android:layout_alignParentRight="true" />

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="确定"
        android:id="@+id/button3"
        android:layout_toLeftOf="@id/button"
        android:layout_alignBottom="@+id/button" />

</RelativeLayout>

152025_8r6S_2861931.png

 

转载于:https://my.oschina.net/316258954/blog/725656

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值