RelativeLayout attribute details

RelativeLayout attribute details
RelativeLayout是相对布局控件:以控件之间相对位置或相对父容器位置进行排列。

相对布局常用属性:

子类控件相对子类控件:值是另外一个控件的id

android:layout_above----------位于给定DI控件之上
android:layout_below ----------位于给定DI控件之下

android:layout_toLeftOf -------位于给定控件左边
android:layout_toRightOf ------位于给定控件右边

android:layout_alignLeft -------左边与给定ID控件的左边对齐
android:layout_alignRight ------右边与给定ID控件的右边对齐
android:layout_alignTop -------上边与给定ID控件的上边对齐
android:layout_alignBottom ----底边与给定ID控件的底边对齐

android:layout_alignBaseline----对齐到控件基准线

相对父容器,值是true或false
android:layout_alignParentLeft ------相对于父靠左
android:layout_alignParentTop-------相对于父靠上
android:layout_alignParentRight------相对于父靠右
android:layout_alignParentBottom ---相对于父靠下

android:layout_centerInParent="true" -------相对于父即垂直又水平居中
android:layout_centerHorizontal="true" -----相对于父即水平居中
android:layout_centerVertical="true" --------相对于父即处置居中

相对于父容器位置:

android:layout_margin="10dp"
android:layout_marginLeft
android:layout_marginRight
android:layout_marginTop
android:layout_marginBottom

版本4.2以上相对布局新属性

android:layout_alignStart---------------------将控件对齐给定ID控件的头部
android:layout_alignEnd----------------------将控件对齐给定ID控件的尾部
android:layout_alignParentStart--------------将控件对齐到父控件的头部
android:layout_alignParentEnd---------------将控件对齐到父控件的尾部

For example:activity_main.xml
<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"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >

<TextView
android:id="@+id/user_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/user_name"
android:layout_alignParentTop="true"
android:text="@string/user_text"
android:textSize="20sp" />
<EditText
android:id="@+id/user_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_toRightOf="@+id/user_text"
android:inputType="text"
android:hint="@string/user_alert"
android:textSize="20sp" />

<TextView
android:id="@+id/pass_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/user_text"
android:layout_alignBottom="@+id/pwd"
android:text="@string/pass_text"
android:textSize="20sp" />
<EditText
android:id="@+id/pwd"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/user_name"
android:layout_toRightOf="@+id/pass_text"
android:inputType="textPassword"
android:hint="@string/pass_alert"
android:textSize="20sp" />
<CheckBox android:id="@+id/check_save"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/pass_text"
android:text="@string/check_save"
android:textSize="20sp" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/check_save"
android:text="@string/login_text"
android:onClick="onLoginCeck"
android:textSize="20sp"
/>

</RelativeLayout>

MainActivity.java
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值