FrameLayout in Android

We have see RelativeLayout and LinearLayout in our last posts. By using this layouts we can adjust views in relative to each other or in regular format. But what if we have to make some UI like overlapping each other, see below image. This is impossible with LinearLayout and RelativeLayout.


FrameLayout is most useful layout in Android when we need to make some UI to be overlapped each other. All children view does’t related to any other views. We can able to control position of child view within the FrameLayout by assigning gravity to each child, using the android:layout_gravity attribute.

Remark: All views in FrameLayout are like stack.  It's mean recent added view placed and show on top so we have to attention on order of view when we create it.

Let’s see example of FrameLayout. Make new project and write code in activity_main.xml file.

now we don’t need any Java code, so simple

In this example we have one TextView which is placed first and then one ImageView added after that. So this ImageView is overlapped on TextView. Now we have add other TextView, so this TextView is also overlapped on ImageView as per order.

Now run project. Our output look like this.


Download Project.


Now see next tutorial ScrollView in Android.

  • Android Boy

    Nice tutorial..!!