Android FrameLayout Example

The Android FrameLayout is one of the lesser used layouts in the Android system, but it definitely has its purposes. The main reason you’d use a FrameLayout is when you only want to show one View at a time inside that FrameLayout. You can think of the Views as if they were in a stack with the most recently added View at the top.
Let’s walk through a simple example. The following code will first draw a red square with width 250dp in the FrameLayout and then draw a white square with width 150dp in the FrameLayout. Since the white square comes after the red square, the white square will be drawn on top of the red square.
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/mainlayout"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <!-- kvarela: Red square -->
    <View
        android:layout_width="250dp"
        android:layout_height="250dp"
        android:background="#FFFF0000" />

    <!-- kvarela: White square -->
    <View
        android:layout_width="150dp"
        android:layout_height="150dp"
        android:background="#FFFFFFFF" />
</FrameLayout>

Here’s a screen shot:

FrameLayout Example
FrameLayout Example