zoukankan      html  css  js  c++  java
  • [Android] 记录相对位置布局

    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>

  • 相关阅读:
    mysql03聚合函数
    栈、队列、循环队列、双端队列、优先级队列04
    OOAD之策略模式(1)
    jvm01:java内存区域与内存
    Python+Selenium
    Python+Selenium
    Python+Selenium
    Python+Selenium
    Python+Selenium
    Python+Selenium
  • 原文地址:https://www.cnblogs.com/fphuang/p/8813517.html
Copyright © 2011-2022 走看看