Android Layout and Views - Types and Examples - DataFlair
Android Layout and Views - Types and Examples - DataFlair
A View is a simple building block of a user interface. It is a small rectangular box that can be TextView, EditText, or even a
button. It occupies the area on the screen in a rectangular area and is responsible for drawing and event handling. View is a
superclass of all the graphical user interface components.
If you have not tried it, refer DataFlair hello world app in Android.
TextView
EditText
Button
Image Button
Date Picker
RadioButton
CheckBox buttons
Image View
And there are some more components. Learn more about Android UI Controls.
LinearLayout
RelativeLayout
FrameLayout
GridView
ListView
Here is how Views and ViewGroups are linked:
Now that we’ve learned about the view and view groups and also somewhat about the layouts. Subsequently let us see the
types of Layouts in Android, that are as follows:
Linear Layout
Relative Layout
Constraint Layout
Table Layout
Frame Layout
List View
Grid View
Absolute Layout
WebView
ScrollView
These are the types of layouts and out of them we’ll learn about the two very important layouts:
1. Linear Layout
We use this layout to place the elements in a linear manner. A Linear manner means one element per line. This layout creates
various kinds of forms on Android. In this, arrangement of the elements is in a top to bottom manner.
2. Relative Layout
This layout is for specifying the position of the elements in relation to the other elements that are present there.
In the relative layout, alignment of the position of the elements to the parent container is possible. To define it in such a way,
we write the following:
android:layout_alignParentTop= “true”
android:layout_alignParentLeft= “true”
If we write the above code, the element will get aligned on the top left of the parent container.
If we want to align it with some other element in the same container, it can be defined is as follows:
android:layout_alignLeft= “@+id/element_name”
android:layout_below= “@+id/element_name”
This will align the element below the other element to its left.