Android的學習第六章(布局二--RelativeLayout)

來源:互聯網
上載者:User

標籤:ack   XML   layout   最大   處理   gre   背景   relative   android布局   

今天我們來說一下Android布局中的Relativelayout布局(相對布局)

  根據英譯過來意思是相對布局,很容易理解,這一樣布局使用的是元素與元素之間的微調做到布局的

  含義:通過元素與元素之間的微調進行布局;

  好處:可以進行細節上的處理

  壞處:元素之間的關係過強,可能一個元素的改變其他元素的情況發生

 

我們看一下下面的一個代碼布局案例

<!--     第一個相對布局這裡我們可以當做最大父元素    設定了寬度高度佔滿父元素 --><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"    xmlns:tools="http://schemas.android.com/tools"    android:layout_width="match_parent"    android:layout_height="match_parent"    tools:context="com.example.activitylife.MainActivity">    <!--         第二個相對布局        這裡設定了寬度佔滿父元素高度200dp背景色為藍色     -->    <RelativeLayout                 android:layout_width="match_parent"        android:layout_height="200dp"        android:background="@android:color/holo_blue_bright"></RelativeLayout>    <!--         第三個相對布局        這裡設定了寬度佔滿父元素高度100dp背景色為綠色     -->    <RelativeLayout                 android:layout_width="match_parent"        android:layout_height="100dp"        android:background="@android:color/holo_green_dark"></RelativeLayout>        </RelativeLayout>

效果是:

  

我們將代碼改一下

  

<!--     第一個相對布局這裡我們可以當做最大父元素    設定了寬度高度佔滿父元素 --><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"    xmlns:tools="http://schemas.android.com/tools"    android:layout_width="match_parent"    android:layout_height="match_parent"    tools:context="com.example.activitylife.MainActivity">    <!--         第二個相對布局        這裡設定了寬度佔滿父元素高度200dp背景色為藍色                這裡我們為第二個相對布局添加了一個id為rel1     -->    <RelativeLayout         android:id="@+id/rel1"        android:layout_width="match_parent"        android:layout_height="200dp"        android:background="@android:color/holo_blue_bright"></RelativeLayout>    <!--         第三個相對布局        這裡設定了寬度佔滿父元素高度100dp背景色為綠色                這裡我們為第三個相對布局天添加了一個屬性為        android:layout_below指的是當前的元素至於某個元素之下        我們將這個元素至於id為rel1元素的底部     -->    <RelativeLayout         android:layout_below="@id/rel1"        android:layout_width="match_parent"        android:layout_height="100dp"        android:background="@android:color/holo_green_dark"></RelativeLayout>        </RelativeLayout>

  

  

 

  以上就是對相對布局的簡單介紹了,希望能對大家有所協助

 

Android的學習第六章(布局二--RelativeLayout)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.