Layout in XML


A layout defines the visual structure for a user interface, such as the UI for an activity or app widget. 

Declare UI elements in XML:  Android provides a straightforward XML vocabulary that corresponds to the View classes and subclasses, such as those for widgets and layouts.

Instantiate layout elements at runtime: Your application can create View and ViewGroup objects (and manipulate their properties) programmatically.

Android Activity doesn’t contain anything of its own. It loads a layout i.e declared in  /res/layout  folder in the project directory.

Layouts are important to your Android applications, which is why Layouts have their very own
layout folder in the standard project resource folder architecture for Android.
Initially android project directory has a activity_main.xml file which defines the elements of the activity. Every class when act as an activity must extends Activity class and override onCreate() method.

This onCreate() method to push it onto your screen on the startup of your application activity.

Lets take a look to the activity_main.xml file:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android=""
    android:orientation="vertical" >

        android:text="Small Text"
        android:textAppearance="?android:attr/textAppearanceSmall" />


Lets have a look to the code (How to Load the xml layout):

public class MainActivity extends Activity {

                public void onCreate(Bundle savedInstanceState) {

The advantage to declaring your UI in XML is that it enables you to better separate the presentation of your application from the code that controls its behavior. Your UI descriptions are external to your application code, which means that you can modify or adapt it without having to modify your source code and recompile.

There are various types of Layouts few of them are:
·         Linear Layout
·         Relative Layout
·         Table Layout
·         Grid View
·         Tab Layout
·         List View

 Reach us At: - 0120-4029000 / 24 / 25 / 27 / 29 Mbl: 9953584548
Write us at: - and

No comments:

Post a Comment