Android學習筆記:FrameLayout布局基礎

來源:互聯網
上載者:User

標籤:android   style   blog   http   io   sp   檔案   on   2014   

FrameLayout布局的特點是:所有放在布局裡的視圖組件,都按照層次堆疊在螢幕的左上方,後面的視圖組件覆蓋前面的。

當然,組件本身是可以控制自己的內部布局的。

一種常見的情境是可以在FrameLayout上放多個圖片視圖,來實現動畫。

我們來看一個簡單例子:

1、建立一個app

2、建立主Activity,該Activity採用的是 FrameLayout布局,其布局檔案的內容如下:

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

    ................

 >

<Button
     android:id="@+id/button1"
     android:layout_width="400px"
     android:layout_height="400px"
     android:background="#888888"
/>

<Button
     android:id="@+id/button2"
     android:layout_width="300px"
     android:layout_height="300px"
     android:background="#555555"
/>

<Button
     android:id="@+id/button3"
     android:layout_width="200px"
     android:layout_height="200px"
     android:background="#222222"
/>

</FrameLayout>

3、運行該App,可以看到相應的效果。如果是採用eclipse開發,直接查看布局檔案對應的Graphical視圖就能看到同樣效果,如下:

可以看出,第一個按鈕(尺寸最大的)是位於最下層,第2個按鈕在它的上面,第3個按鈕又在最上面。

在這個最基礎的特性基礎之上,結合視圖的隱藏或透明背景等屬性,可以實現各種特殊的顯示方式。

 注意:千萬不要把FrameLayout 與 Fragment混淆了,這兩者完全沒關係,前者是視圖的一種布局方式,後者是一種視圖組件。

Android學習筆記:FrameLayout布局基礎

聯繫我們

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