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

xmlns:android=" http://schemas.android.com/apk/res/android"

android:layout_width="fill_parent"

android:layout_height="fill_parent"

android:orientation="vertical"

>

  

   android:layout_above="@+id/bt2"

android:layout_width="fill_parent"

android:layout_height="fill_parent"

android:background="#ff00ff00"

android:layout_marginTop="-50dip"

/>

更多相关文章

  1. Android 如何自己定义控件的样式 Shape
  2. TabHost布局及新浪式TabHost布局
  3. 请介绍下Android中常用的五种布局
  4. 边缘图片android布局属性详解
  5. androidUI设计之旅 ----布局文件属性解析

随机推荐

  1. Android Binder机制分析
  2. Android---App Inventor环境搭建
  3. Android 核心分析 之五基本空间划分
  4. android触屏事件处理onInterceptTouchEve
  5. Android的四大组件之三--Activity(4)----->
  6. Android培训班(46)
  7. Android(安卓)IPC框架分析 Binder,Service
  8. Android内存分析和优化
  9. Android:手机扫描局域网所有ip,并进行sock
  10. Android如何通过https协议下载自己的http