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 如何自己定义控件的样式 Shape
  2. TabHost布局及新浪式TabHost布局
  3. 请介绍下Android中常用的五种布局
  4. 边缘图片android布局属性详解

随机推荐

  1. linux下android开发环境的配置
  2. android 开源项目集锦
  3. ubuntu android 调用 动态链接库
  4. Android布局优化
  5. android button 自定义
  6. Android Design版微信首度亮相:微信的一小
  7. Android之Android(安卓)Studio三种方式导
  8. Android图像处理技术(实现Android中的PS)(一
  9. Android点击WebView网页中的email发送邮
  10. Android 仿微信的键盘切换