Android布局---相對布局

來源:互聯網
上載者:User

標籤:

Android布局分為五大類:相對布局、線性布局、表格版面配置、幀布局、網格布局

 

相對布局

文法格式:

<RelativeLayout

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

  xmls:tools=""http://schemas.android.com/tools

  android:layout_width=" "

  android:layout_height=" ">

 

  <Widgets>

    android:id="@+id/ "

    android:layout_width="wrap_content"

    android:layout_height="wrap_content"

 

    android:layout_centerHorizontal=" "

    android:layout_alignParentLeft=" "

    android:layout_marginLeft=" "

  </Widgets>

 

</RelativeLayout>

 

相對父容器布局的文法屬性

  屬性名稱                                     屬性說明

  layout_alignParentLeft                以父容器的左邊緣為參照標準

      layout_marginLeft                      控制項左邊緣距離父容器左邊緣的距離

  layout_alignParentRigth              以父容器的有邊緣為參照標準

  layout_marginRight                    控制項右邊緣距離父容器右邊緣的距離

    layout_alignParentTop       以父容器的上邊緣為參照標準

  layout_marginTop        控制項上邊緣距離父容器上邊緣的距離

  layout_alignParentBottom      以父容器下邊緣為參照標準

  layout_marginBottom      控制項下邊緣距離父容器下邊緣的距離

      layout_centerHorizontal      控制項在父容器中水平置中

      layout_centerHorizontal      控制項在父容器中垂直置中

  layout_centerInParent       控制項在父容器中央

 

例子:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">

<Button
android:id="@+id/btn1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"

android:layout_alignParentTop="true"
android:layout_marginTop="128dp"
android:layout_centerHorizontal="true"
android:text="button1" />

</RelativeLayout>





相對控制項布局的文法屬性
  屬性名稱         屬性說明
  layout_alignLeft      以已知控制項的左邊緣為參照標準
  layout_marginLeft      控制項的左邊緣與已知控制項之間的距離
  layout_alignRight     以已知控制項的右邊緣為參照標準
  layout_marginRight 控制項的右邊緣與已知控制項之間的距離
  layout_alignTop 以已知控制項的上邊緣為參考標準
layout_marginTop     控制項的上邊緣與已知控制項之間的距離
  layout_alignBottom     以已知控制項的下邊緣為參考標準
  layout_marginBottom    控制項的下邊緣與已知控制項之間的距離
  layout_alignBaseLine    以已知控制項的BaseLine為參考標準

  layout_toRightOf      控制項位於已知控制項的右側
  layout_toLeftOf       控制項位於已知控制項的左側
  layout_above       控制項位於已知控制項的上側
layout_below        控制項位於已知控制項的下側

例子
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="match_parent">

<Button
android:id="@+id/btn1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"

android:layout_centerInParent="true"
android:text="button1"/>

<Button
android:id="@+id/btn2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"

android:layout_alignBottom="@+id/btn1"
android:layout_marginBottom="85dp"
        android:layout_toRightOf="@+id/btn1"
android:text="button2"/>

</RelativeLayout>


Android布局---相對布局

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.