relative 采用相对某个控件的形式定义布局,基本形式如下:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:layout_width="fill_parent"    android:layout_height="fill_parent" >

其属性有如下几类:

1、相对于给定控件,如:

    <Button        android:id="@+id/button2"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:layout_alignBottom="@+id/button1"        android:layout_alignLeft="@+id/button1"        android:text="Button2" />

包括:

android:layout_above     将该控件的底部置于给定ID的控件之上;

android:layout_below     将该控件的底部置于给定ID的控件之下;

android:layout_toLeftOf   将该控件的右边缘与给定ID的控件左边缘对齐;

android:layout_toRightOf 将该控件的左边缘与给定ID的控件右边缘对齐;

android:layout_alignBaseline 将该控件的baseline与给定ID的baseline对齐;

android:layout_alignTop 将该控件的顶部边缘与给定ID的顶部边缘对齐;

android:layout_alignBottom 将该控件的底部边缘与给定ID的底部边缘对齐;

android:layout_alignLeft 将该控件的左边缘与给定ID的左边缘对齐;

android:layout_alignRight 将该控件的右边缘与给定ID的右边缘对齐;

2、相对于父组件

    <Button        android:id="@+id/button6"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:layout_alignBaseline="@+id/button4" //定义父组件        android:layout_alignParentRight="true"        android:text="Button" />

包括:

android:layout_alignParentTop 如果为true,将该控件的顶部与其父控件的顶部对齐;

android:layout_alignParentBottom 如果为true,将该控件的底部与其父控件的底部对齐;

android:layout_alignParentLeft 如果为true,将该控件的左部与其父控件的左部对齐;

android:layout_alignParentRight 如果为true,将该控件的右部与其父控件的右部对齐;

3、指定偏移,包括:

android:layout_marginTop 上偏移的值;

android:layout_marginBottom 下偏移的值;

android:layout_marginLeft   左偏移的值;

android:layout_marginRight   右偏移的值;

该偏移主要是针对相对控件(即属性类别1)而言,如下例图示:

    <Button        android:id="@+id/button2"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:layout_alignLeft="@+id/button1"        android:layout_centerVertical="true"        android:layout_marginLeft="52dp"  //针对layout_alignLeft        android:text="Button" />

布局(2、相对布局)

备注:

通过android:background="#FFFF0000" 修改布局颜色,其他布局方式同此。

更多相关文章

  1. android 设置布局为无标题样式
  2. Android 解决布局问题
  3. android xml 常用控件介绍
  4. android卡片布局CardView
  5. AndroidのUI布局之layout weight
  6. Android_布局属性大全
  7. Android控件之ImageView,Button, ImageButton
  8. Android Button 控件绑定单击事件

随机推荐

  1. Android debug.keystore的密码
  2. Android:网络框架android-async-http 1.4
  3. Android中的popWindow
  4. 【Android 应用开发】Android 开发 之 JN
  5. Webkit 3
  6. Android 如何在XML文件中定义动画
  7. Android开发,使用背景图(xml drawable)为vie
  8. Android ViewFlipper的动画
  9. Android学习之路四:ImageView
  10. Android关于java.lang.NoClassDefFoundEr