本節(jié)引言
FrameLayout(幀布局)可以說是六大布局中最為簡單的一個布局,這個布局直接在屏幕上開辟出一塊空白的區(qū)域,當我們往里面添加控件的時候,會默認把他們放到這塊區(qū)域的左上角,而這種布局方式卻沒有任何的定位方式,所以它應用的場景并不多;幀布局的大小由控件中最大的子控件決定,如果控件的大小一樣大的話,那么同一時刻就只能看到最上面的那個組件!后續(xù)添加的控件會覆蓋前一個!雖然默認會將控件放置在左上角,但是我們也可以通過layout_gravity屬性,指定到其他的位置!本節(jié)除了給大家演示一個最簡單的例子外,還給大家?guī)Я藘蓚€好玩的例子,有興趣的可以看看!
1.常用屬性
FrameLayout的屬性很少就兩個,但是在說之前我們先介紹一個東西:
前景圖像:永遠處于幀布局最上面,直接面對用戶的圖像,就是不會被覆蓋的圖片。
兩個屬性:
android:foreground:*設置改幀布局容器的前景圖像
android:foregroundGravity:設置前景圖像顯示的位置
2.實例演示
1)最簡單的例子
運行效果圖:
23622209
實現(xiàn)代碼如下:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/FrameLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
android:foreground="@drawable/logo"
android:foregroundGravity="right|bottom">
<TextView
android:layout_width="200dp"
android:layout_height="200dp"
android:background="#FF6143" />
<TextView
android:layout_width="150dp"
android:layout_height="150dp"
android:background="#7BFE00" />
<TextView
android:layout_width="100dp"
android:layout_height="100dp"
android:background="#FFFF00" />
</FrameLayout>