Android RelativeLayout 属性

// 相对于给定ID控件

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的右边缘对齐;

// 相对于父组件

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

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

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

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

// 居中

android:layout_centerHorizontal 如果为true,将该控件的置于水平居中;

android:layout_centerVertical 如果为true,将该控件的置于垂直居中;

android:layout_centerInParent 如果为true,将该控件的置于父控件的中央;

// 指定移动像素

android:layout_marginTop 上偏移的值;

android:layout_marginBottom 下偏移的值;

android:layout_marginLeft   左偏移的值;

android:layout_marginRight   右偏移的值;

example:

1.

android:layout_below = "@id/***"

android:layout_alignBaseline = "@id/***"

android:layout_alignParentTop = true

android:layout_marginLeft = “10px”

2. 使用RelativeLayout实现叠加的效果上面的view覆盖下面的view。

对任何布局,通过android:layout_marginXXX等属性设置为负值来实现相邻view之间的叠加效果,

例如:

android:layout_marginTop="-50dip" 可实现与相邻的顶端view叠加50dip区域的效果。

但是,谁叠加在谁的上面是由他们在xml文件中的描述顺序决定的, 后出现的会在上面。
因此如果要让布局上面的view覆盖在下面的view之上,不能使用LinearLayout。因为, 对于LinearLayout,在xml文件中的描述view时,必须先描述上方的view,让后描述下方的view,所以下方view的会覆盖在上方view之上。
可以使用RelativeLayout。因为在Relativelayout的布局中,我们可以先描述处于下方的view,后描述上方的view。(注意, 此时先描述的View需要使用后描述的view的ID, 需要使用"@+id/相应的viewID")
例如:下面就是蓝色的button会覆盖绿色button之上的例子

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

android:orientation="vertical"

>

<Button android:layout_below="@+id/bt1"

android:layout_above="@+id/bt2"

android:layout_width="fill_parent"

android:layout_height="fill_parent"

android:background="#ff00ff00"

android:layout_marginTop="-50dip"

/>

<Button android:id="@+id/bt1"

android:layout_width="fill_parent"

android:layout_height="100dip"

android:background="#ff0000ff"

/>

<Button android:id="@+id/bt2"

android:layout_alignParentBottom="true"

android:layout_width="fill_parent"

android:layout_height="100dip"

android:background="#ff0000ff"

/>

</RelativeLayout>

更多相关文章

  1. Android开发---从简单的TextView看Android的控件显示方式
  2. Android深入浅出自定义控件(一)
  3. Android(安卓)自定义组合控件小结
  4. Android(安卓)布局 之 TableLayout,RelativeLayout,AbsoluteLayout
  5. 【Android】@+id与@id的区别
  6. Android(安卓)UI开发专题(四) View自绘控件
  7. Android及Robotium学习总结【环境…
  8. 如何让TextView中的文字居中显示
  9. 关于Android的开发经验总结

随机推荐

  1. 2019年Android开发者常见面试题(一)
  2. 编写高效的Android代码 .
  3. Android图片特效处理(像素处理)
  4. Android小白进阶之路--项目需求2
  5. Android取日志的实用方法,Notepad++插件—
  6. 回调机制在 Android(安卓)监听用户界面操
  7. android注入so,有代码有命令
  8. 单击事件与触摸事件的区别
  9. 转:抗锯齿方法两种(其一:paint.setAntiAlias
  10. Android(安卓)4.1性能分析的一般步骤(二)