Android :: What is frame layout and how to create one?

In our previous article relating to Android Programming which was  Android :: How to create layout for an activity? we explained how we can create layout for an activity and how we can attach the layout to an activity. Today’s topic is about Frame Layout and we will cover what a Frame Layout is and how we can make one.

As explained in the previous article there are various layouts available in android which can be used to make user interfaces and align user interface controls on screen. Frame Layout is one of the layouts available in android to make user interface. Android user interface is largely based on webpages type of user interface.

Like you add an interface to a webpage using HTML same way you add interface to android application using XML.

What is a Frame Layout?

Frame Layout is the most easy layout available in android. Frame Layout adds child views on top of each other on left side i.e. if you add a text view in frame layout it will be added to top left side of the layout and then if you add a edit box view it will be added above text view on top left side of the layout.

In order to create a Frame Layout you have to follow the following steps:

Create or open an existing project and while in the project click on:

File->New-AndroidXML File option in the eclipse menu. You will see a window like below:

Frame Layout

Frame Layout

In this dialog choose Frame Layout and add in File Name to the same and click finish. After doing the same you will see the xml file listed under res->layouts folder in eclipse with the following code:

<?xml version=”1.0″ encoding=”utf-8″?>
<FrameLayout xmlns:android=””
android:layout_height=”match_parent” >


In the above code the <FrameLayout> and </FrameLayout> defines that the layout being used is a frame layout. The  xmlns:android=”” passed the name space of xml provided by android defined for Frame Layout.     android:layout_width=”match_parent” is used to tell what will the width be for the layout match_parent means width is equal to the width in which this layout is being used. Same way android:layout_height=”match_parent” defines what the height for the layout will be.

You can now add views inside the <FrameLayout> and </FrameLayout> tags according to needs. We will detail adding new views in the frame layout in our next article.

We will keep updating our Android Programming Tips section every 4 days, please subscribe to our feed and also share our articles on Facebook and Google Plus so other’s can benefit from our insight. Please feel free to send us your comments below, on how we can improve.

No comments yet.

Leave a Reply