一.FrameLayout介紹:
FrameLayout是五大布局中最簡單的一個佈局,在這個佈局中,整個界面被當成一塊空白備用區域,所有的子元素都不能被指定放置的位置,它們統統放於這塊區域的左上角,並且後面的子元素直接覆蓋在前面的子元素之上,將前面的子元素部分和全部遮擋。
1.在FrameLayout中添加普通的View
在FrameLayout中可以添加諸如imageView和TextView這樣簡單的View,它們層層向上疊加,上層遮蔽下層,代碼示例如下:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<ImageView
android:id="@+id/image1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:src="@drawable/sky"/>
<ImageView
android:id="@+id/image2"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:src="@drawable/cloud"/>
<ImageView
android:id="@+id/image3"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:src="@drawable/sun"/>
</FrameLayout>
圖片層層疊加,只顯示上層圖片
2.在FrameLayout中利用<include>標籤添加自定義的xml文件
<FrameLayout
android:id="@+id/circleView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical" >
<include
layout="@layout/circle_view"/>
<include
layout="@layout/circle_view2"/>
</FrameLayout>
3.在FrameLayout中引用自定義的view類文件
<FrameLayout
android:id="@+id/circleView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical" >
<com.example.viewflipperdemoactivity.CircleView
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
<TextView
android:layout_width="fill_parent" />
</FrameLayout>
二.設置FrameLayout中的某個View透明
由於FrameLayout層層疊加的特性,使得下層View被上層View遮蔽,有時爲了讓下層View可見,就不得不讓上層View透明:
View.getBackground().setAlpha(100);