UI of an Android application is defined using the XML file.XML files are located in the res/layout folder of the project.XML file contains widgets or views arranged using layouts.
View and ViewGroups are the classes which are used to develop the UI of an activity. ViewGroup doesn’t provide any UI on it’s own but is rather used to arrange the Views.A ViewGroup contains multiple views inside it.ViewGroup is also know as Layout Manager.A ViewGroup derives from the base class android.view.ViewGroup.
A view is a widget that has an appearance on screen.Examples of views are buttons, labels, and text boxes. A view derives from the base class android.view.
Layout is a type of ViewGroup.It is a container which contains other views.Following layouts are available in Android:
- FrameLayout Used to contain a single view.
- LinearLayout Arranges views either in a single row or single column.
- TableLayout Views are arranged in multiple rows and columns.A single row is created using the TableRow element.
- GridLayout Views are arranged in a Grid which consists of rows and columns
- RelativeLayout Position of Views is indicated relative to each other or the parent
Following is an example of a XML which defines the UI.
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <TextView android:layout_width="100dp" android:layout_height="wrap_content" android:text="@string/sample"/> <Button android:layout_width="160dp" android:layout_height="wrap_content" android:text="Button"/> </LinearLayout>
Leave a Reply