Android :: How to add views inside the Frame Layout?

In our previous article which was Android :: What is frame layout and how to create one?  we discussed what a Frame Layout is and how we can make one. Today’s topic is how we can add views inside the frame layout and how we can adjust the UI inside the Frame Layout.

View are the UI controls which are available in android for you to use to make interactive applications. As is the case with any programming and views like in Windows Development and in Mac Development the view can be overridden and you can make your own views or change the design pattern of views for the application you are creating. I know that this can lead to alot of excitement and you can have the urge to design and redesign the same views again and again. But remember no one gains by reinventing the wheel. Use default views where needed or advised because similar UI is easier for users to understand and they can grasp the UI and your application easily.

What kind of views are available in the android system?

There are many views which have been designed for android and you can use any or all of them in your application depending on your needs. The main views available are:

  • Edit View
  • List View
  • Expandable List View
  • TextView (There are many sub text views which are available as well).
  • Button
  • Checkbox
  • Radio Button
  • Checked TextView
  • Spinner
  • ProgressBar
  • SeekBar
  • Radio Group
  • Tab View
  • Image View
  • Image Button
  • Gallery
  • Media Controller
  • Video View
  • and many more…

We will be discussing about each of these views in details in our future articles. Right now our topic is how to add views to the Frame Layout we created in our previous article. To do the same follow the following points:

  • Open the project containing the Frame Layout xml file.
  • Open the XML file in eclipse and you will see Graphical Layout and XML name edit tab at bottom.
  • Click on Graphical Layout tab and you will see a dialog like below:
Frame Layout Views

Frame Layout Views

In the above dialog you can see that Eclipse provides a graphical interface to add views inside the layout. You can in the same dialog just drag and drop the view from left side to right side and drag and drop the views on right side to adjust the layout as you want.

You can also add the views in the layout directly via the XML file as well.  To add the views using the XML click on the frame_layout.xml tab in the above window. You will see the code like:

<?xml version=”1.0″ encoding=”utf-8″?>
<?xml version=”1.0″ encoding=”utf-8″?>
<FrameLayout xmlns:android=”http://schemas.android.com/apk/res/android”
android:layout_width=”match_parent”
android:layout_height=”match_parent” >

</FrameLayout>

In the above code you can add in the EditText view by adding in the following code inside the <FrameLayout> and </FrameLayout>.

<EditText
android:id=”@+id/editText1″
android:layout_width=”match_parent”
android:layout_height=”wrap_content”
android:ems=”10″ >

<requestFocus />
</EditText>

In the above code android:id=”@+id/editText1″ defines the id which will be used in java to get value or set value for this view. android:layout_width = “match_parent” and android:layout_height=”wrap_content” provides width and height for the view.

In this article we learned how we can add views to Frame Layout via the graphical interface and also directly from the XML file. In our next article we will discuss what RelativeLayout is and how we can add views in the RelativeLayout.

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