A layout defines what a screen look like and we define itusing XML.The Layouts consists of widgets like TextView,EditText,Buttons. The user interacts with the layout to do some task or to perform some functionality.
Two Key Layouts: Linear and Relative layout
1)Linear Layout :A Linear layout either display its view in horizontal or vertical direction.If the linear layout is vertical,it will be displayed in single column or if the linear layout is horizantal,it will be displayed in form of a row.
There are three necessary attributes which must be initialised android:layout_width, android:layout_height and android:orientation.
The width and height attribute can take predefined value like match_parent(occupy the full width and height of the parent) or wrap_content(occupy only that width and height in which it can fit itself) or you can specify any integer value.
Orientation can take two values horizontal or vertical.
The widget will appear in the same order in which we put widgets in linear layout.
There is no relative positioning between the widgets.
We only specify the id of the widgets in linear layout for which we are going to refer in our activity code.
We use gravity attribute to specify where widgets in a layout.
2) Relative Layout:
It displays its views in relative to each other.We need to define the position of each view relative to other views in the layout or relative to the parent.
There are two necessary attributes which must be initialised android:layout_width, android:layout_height.
Aligning the view relative to parent:
Ex:
1) android:layout_alignParentTop="true"
2) android:layout_alignParentRight="true


Comments
Post a Comment