Thursday, May 3, 2012

Tutorial 2: Understanding Android Layouts


In Android, there are various types of layouts available which are used to design the screen or we can say, are used to arrange the order of various widgets(like- TextView, EditText, Button, Image, ImageButton etc.) in the required manner. In Android terms, the layouts are called as ViewGroups and widgets are called as Views.

The wise use of different layouts in the screen can reduce the development time and effort and even can save you from the later stage issues (like- inserting more widgets in the screen in later stage, porting to different screen resolutions, we will discuss it in the upcoming posts).

So, Lets start understanding the behavior of different layouts:

Linear Layout: Linear layout arranges all the children widgets in one direction like- vertical or horizontal as shown in the image.
So, where ever we want some widgets to be aligned in a single direction, we can make use of Linear Layout.


Remember that designing the android screen goes from top to down fashion.



Android has given three amazing properties- wrap_content, match_parent, fill_parent to declare the height and width of the layouts and widgets. The one should make use of them very wisely. Never practice declaring the absolute height and width of any view. The best way is to use property wrap_content maximally.

Relative Layout: Relative layout arranges the children widgets relative to the parent layout or relative to each other. Best way to understand it, look at the image.
Table Layout: Table layout arranges the children widgets in the table, i.e. rows and columns, look at the image.
Frame Layout: Frame layout arranges the children widgets relative to top left point. In this way, the widgets may get overlapped as shown in the image.
Absolute Layout: Absolute layout pins the children widgets in the coordinate points as shown in the image.
However, this layout is advised not to practice as it raises the issues while designing the same layout for different screen resolutions. Even it has been deprecated in the latest versions of Android.

Please post your feedbacks/challenges J




No comments:

Post a Comment