Android 程式開發:(五)螢幕組件 —— 5.6 FrameLayout幀布局

來源:互聯網
上載者:User

FrameLayout就是螢幕上的一個“定位器”,可以使用它去顯示一個單一的視圖。被添加到FrameLayout上的視圖views總是被固定在這個布局的左上方。考慮以下的代碼:

 
  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"  
  3.     android:id="@+id/RLayout"  
  4.     android:layout_width="fill_parent"  
  5.     android:layout_height="fill_parent" >  
  6.   
  7.     <TextView  
  8.         android:id="@+id/lblComments"  
  9.         android:layout_width="wrap_content"  
  10.         android:layout_height="wrap_content"  
  11.         android:layout_alignParentLeft="true"  
  12.         android:layout_alignParentTop="true"  
  13.         android:text="Hello, Android!" />  
  14.   
  15.     <FrameLayout  
  16.         android:layout_width="wrap_content"  
  17.         android:layout_height="wrap_content"  
  18.         android:layout_alignLeft="@+id/lblComments"  
  19.         android:layout_below="@+id/lblComments"  
  20.         android:layout_centerHorizontal="true" >  
  21.   
  22.         <ImageView  
  23.             android:layout_width="wrap_content"  
  24.             android:layout_height="wrap_content"  
  25.             android:src="@drawable/droid" >  
  26.         </ImageView>  
  27.     </FrameLayout>  
  28.   
  29. </RelativeLayout>  
這裡,在RelativeLayout中內嵌了一個FrameLayuout,在FrameLayuout中內嵌了一個ImageView。:

但是,如果想要在這個FrameLayuout中添加另外的view(比如一個Button),那麼這個view就會重疊在“之前的”view上面(本例中是顯示圖片的ImageView)。代碼:

 
  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"  
  3.     android:id="@+id/RLayout"  
  4.     android:layout_width="fill_parent"  
  5.     android:layout_height="fill_parent" >  
  6.   
  7.     <TextView  
  8.         android:id="@+id/lblComments"  
  9.         android:layout_width="wrap_content"  
  10.         android:layout_height="wrap_content"  
  11.         android:layout_alignParentLeft="true"  
  12.         android:layout_alignParentTop="true"  
  13.         android:text="Hello, Android!" />  
  14.   
  15.     <FrameLayout  
  16.         android:layout_width="wrap_content"  
  17.         android:layout_height="wrap_content"  
  18.         android:layout_alignLeft="@+id/lblComments"  
  19.         android:layout_below="@+id/lblComments"  
  20.         android:layout_centerHorizontal="true" >  
  21.   
  22.         <ImageView  
  23.             android:layout_width="wrap_content"  
  24.             android:layout_height="wrap_content"  
  25.             android:src="@drawable/droid" >  
  26.         </ImageView>  
  27.   
  28.         <Button  
  29.             android:layout_width="124dp"  
  30.             android:layout_height="wrap_content"  
  31.             android:text="Print Picture" />  
  32.     </FrameLayout>  
  33.   
  34. </RelativeLayout>  
最終:


摘自 manoel的專欄

聯繫我們

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