Android中的FrameLayout幀布局,androidframelayout

來源:互聯網
上載者:User

Android中的FrameLayout幀布局,androidframelayout

幀布局由FrameLayout所代表,FrameLayout直接繼承了ViewGoup組件。

幀版面配置容器為每個加入其中的組件建立一個空白的地區(稱為一個幀),每個子組件佔據一幀,這些幀都會根據gravity屬性執行自動對齊。

代碼:

<?xml version="1.0" encoding="utf-8"?><FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:layout_width="match_parent"    android:layout_height="match_parent"    android:orientation="vertical" >    <!-- 依次定義6個TextView,先定義的TextView位於底層     後定義的TextView位於上層     --><TextView android:id="@+id/view01"    android:layout_width="wrap_content"    android:layout_height="wrap_content"    android:layout_gravity="center"    android:width="320px"    android:height="320px"    android:background="#f00"    /><TextView     android:layout_width="wrap_content"    android:layout_height="wrap_content"    android:layout_gravity="center"    android:width="280px"    android:height="280px"    android:background="#0f0"    /><TextView     android:layout_width="wrap_content"    android:layout_height="wrap_content"    android:layout_gravity="center"    android:width="240px"    android:height="240px"    android:background="#00f"    /><TextView     android:layout_width="wrap_content"    android:layout_height="wrap_content"    android:layout_gravity="center"    android:width="200px"    android:height="200px"    android:background="#ff0"    /><TextView     android:layout_width="wrap_content"    android:layout_height="wrap_content"    android:layout_gravity="center"    android:width="160px"    android:height="160px"    android:background="#f0f"    /><TextView     android:layout_width="wrap_content"    android:layout_height="wrap_content"    android:layout_gravity="center"    android:width="120px"    android:height="120px"    android:background="#0ff"    /></FrameLayout>

效果:



android中tab為何要用framelayout來布局,不可以選其他的布局方式?

FrameLayout 是單幀布局,是布局的範圍和樣式的限制,用在這裡合適
其他也行,不過麻煩
 
android 的布局檔案中framelayout嵌套framelayout是什

就是在第一個framelayout中再嵌套一個framelayout。不過感覺這樣沒什麼用啊。Layout嵌套是在複雜UI中實現布局的,比如在垂直的LinearLayout中要實現一排水平的按鈕,就可以再嵌套一個水平的LinearLayout,在水平的LinearLayout添加多個按鈕。因為FrameLayout布局的特殊性,我感覺再嵌套一個FrameLayout沒有什麼用。除非是嵌套的FrameLayout是單獨顯示某些資訊的,在需要顯示的時候設定其setVisibility(View.VISIBLE)顯示,不用時設定其setVisibility(View.GONE)不顯示。不知道這樣說的清不清楚。
 

聯繫我們

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