您的位置:首页 > 移动开发 > Android开发

Android - RelativeLayout布局

2014-12-10 08:59 67 查看

RelativeLayout布局

本文地址:http://blog.csdn.net/caroline_wendy

RelativeLayout是一种相对布局方式,是根据属性进行对齐;A Layout where the positions of the children can be described in relation to each other or to the parent.在布局中,子控件的位置根据相互之间的关系进行描述。Note that you cannot have a circular dependency between the size of the RelativeLayout and the position of its children. 子控件之间不能存在循环依赖。
Note: In platform version 17 and lower, RelativeLayout was affected by a measurement bug that could cause child views to be measured with incorrect MeasureSpec values. This was triggered when a RelativeLayout container was placed in a scrolling container, such as a ScrollView or HorizontalScrollView. If a custom view not equipped to properly measure with the MeasureSpec mode UNSPECIFIED was placed in a RelativeLayout, this would silently work anyway as RelativeLayout would pass a very large AT_MOST MeasureSpec instead.This behavior has been preserved for apps that set android:targetSdkVersion="17" or older in their manifest's uses-sdk tag for compatibility. Apps targeting SDK version 18 or newer will receive the correct behavior
属性名称
描述
android:layout_below
摆放在指定组件的下边
android:layout_toLeftOf
摆放在指定组件的左边
android:layout_toRightOf
摆放在指定组件的右边
android:layout_alignTop
以指定组件作为参考进行上对齐
android:layout_algnBottom
以指定组件作为参照进行下对齐
android:layout_alignLeft
以指定组件作为参考进行左对齐
android:layout_alignRight
以指定组件
 
android:layout_toStartOf="@+id/buttonTweet” //表是在某个控件的前对齐,如果不知道,就图形界面拖动
<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:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context=".StatusActivity">

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/button_tweet"
android:id="@+id/buttonTweet"
android:layout_alignParentEnd="true"/>

<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="textMultiLine"
android:ems="10"
android:id="@+id/editText"
android:layout_alignParentBottom="true"
android:layout_alignParentStart="true"
android:hint="@string/hint_status"
android:layout_toStartOf="@+id/buttonTweet"/>

<TextView
android:id="@+id/textCount"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignEnd="@id/buttonTweet"
android:layout_below="@id/buttonTweet"
android:text="140"
android:textAppearance="?android:textAppearanceSmall"/>

</RelativeLayout>


内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息