相对布局中的视图组件是按相互之间的相对位置来确定的, 并不是线性布局中的必须

按行或按列单个显示,主要属性如下:

相对于某一个元素

android:layout_below="@id/aaa" 该元素在 id为aaa的下面

android:layout_toLeftOf="@id/bbb" 改元素的左边是bbb

相对于父元素

android:layout_alignParentLeft="true" 在父元素左对齐
android:layout_alignParentRight="true" 在父元素右对齐
还可以指定边距等,

android:layout_marginLeft="10dip"使当前控件左边空出相应的空间。

具体可以详见API,下面简单归纳一下其属性取值:

第一类:属性值为true或false
*android:layout_centerHrizontal
*android:layout_centerVertical
*android:layout_centerInparent
*android:layout_alignParentBottom
*android:layout_alignParentLeft
*android:layout_alignParentRight
*android:layout_alignParentTop
*android:layout_alignWithParentIfMissing
第二类:属性值必须为id的引用名“@id/id-name”
*android:layout_below
*android:layout_above
*android:layout_toLeftOf
*android:layout_toRightOf
*android:layout_alignTop
第三类:属性值为具体的像素值,如30dip,40px
*android:layout_marginBottom
*android:layout_marginLeft
*android:layout_marginRight
*android:layout_marginTop

如下布局:

<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:layout_width="fill_parent"    android:layout_height="fill_parent" >    <TextView         android:layout_width="fill_parent"        android:layout_height="wrap_content"        android:text="@string/name_text"        android:id="@+id/text"    />    <EditText        android:layout_width="fill_parent"        android:layout_height="wrap_content"        android:layout_below="@id/text"        android:id="@+id/edit"        />    <Button        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:text="@string/cancle_button"        android:layout_alignParentRight="true"        android:layout_below="@id/edit"        android:id="@+id/cancle"        />    <Button        android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_toLeftOf="@id/cancle"android:layout_alignTop="@id/cancle"android:text="@string/ok_button"        /></RelativeLayout>
显示的效果如下:

android 开发布局之RelativeLayout_第1张图片


参考:http://hi.baidu.com/hoyah/item/ac49b0d059c96ae1b2f777f1

整个android的布局和视图可以参考这篇博文点击打开链接。写的非常全!

更多相关文章

  1. Android TextView 属性设置
  2. 安卓入门.RelativeLayout相对布局1
  3. Android中shape属性详解
  4. Android 控件及其属性2
  5. Android属性之android:priority

随机推荐

  1. RelativeLayout 相对布局属性
  2. android实现密码框右侧显示小眼睛
  3. 【整理】Android中EditText中的InputType
  4. GitHub 优秀的 Android 开源项目
  5. [置顶] Android屏幕适配全攻略(最权威的
  6. Android中Button控件Buttons in button b
  7. 21款优秀Android开源库整理推荐
  8. Anddroid各种布局总结
  9. 使用Android Studio与ArcGIS Android SDK
  10. Android技术内幕