Thursday, 27 August 2015

What is layout?

Layout can be considered as a parent and the widgets imposed on it are children. It is the container containing widgets.
There are different types of layouts.
Currently we will go with Relative Layout.
Relative Layout is pre-added, so we do not need to add it in activity.
Whenever we place an object in layout it is placed with respect to/ relative to any other object/objects or the layout itself.

Go to Design view in xml file and pick large text from the widget section.
See the figure carefully. Every object is placed with respect other object
  1.          Widget present at center is placed at horizontal and vertical centers of relative layout
  2.          Widget in upper right section is placed at the most right and top position with respect to layout
  3.          Widget in upper left section is placed with x co-ordinate as left to center widget and y co-ordinate as below by fixed amount of pixels to the top of relative layout
  4.          Widget in bottom left and bottom right section are placed with respect to other parameters

Now, if I select the center widget and delete it then what will happen?
Firstly when we select the center widget then the layout will look like the figure shown below
The other 2 widget which have one co-ordinate (here it is x co-ordinate) dependent on center widget are shown in yellowish color. Now if I delete the center widget then the layout will be how?
Since the parent widget (i.e. deleted widget) is aligned at center for x co-ordinate, the dependent widgets will take center of x co-ordinate for positioning itself.
So, be wise while dealing with relative layout.



No comments:

Post a Comment