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" />

备注:

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

更多相关文章

  1. android中的两端对齐
  2. android中的两端对齐
  3. 代码中如何设置TextView为不可见
  4. Android开发神贴整理
  5. Android学习资源网站
  6. android中的两端对齐
  7. Android(安卓)中使用自定义字体的方法
  8. android xml 常用控件介绍
  9. android中的两端对齐

随机推荐

  1. android wpa_supplicant 调试
  2. Android核心分析 ------ 电话系统之rilD
  3. Android 之各种颜色
  4. 修改SeekBar样式
  5. TextView——行间距与字母间隔
  6. 在android 两个类之间 get,set方法传参使
  7. Android ListView里设置默认Item的背景颜
  8. android中的Inflater
  9. JS判断客户端是否是iOS或者Android手机移
  10. android EditText+ListView的组合(类似于A