User Interface Layouts to Build Dashing Android Application
Android layout class handles the appearance of text and any other graphics on the mobile screen.Any item or category that is viewed can be considered as a child of a layout.
Common hierarchy of layout class follows like this:
- All layoutsinherit from ViewGroup.
- ViewGroup in turn inherits from View class.
Nesting of layouts can be done in similar pattern.User defined class containing custom layout can be defined using ViewGroup.
Standard layouts available are:
FrameLayout is designed to display single item at a time. Programmer can display a wide range of elements within a FrameLayout. Here each element is positioned on top left portion of the screen. At the time of display, if any element is overlapped than it will be displayed overlapping.
It is more useful when elements are hidden and logically display for any action is done. For example, “Game Over” text to be displayed when game is over.
“Android:visibility” attribute is used in XML to hide any element in program. “setVisibility” attribute can also be used to perform the same task. Values that are available are: Visible, Gone, and Invisible.
Invisible value does not display on the screen but will occupy the memory space in the layout whereas “gone” value will not show up on the screen and also will not take space in layout.
RelativeLayout is based on the relationship with each element with other element; and with parent container. It is the most complicated layout to use and developer need to define different properties to actually get the desired layout.
AbsoluteLayout follows simple concept of placing every control at an absolute position.Programmer needs to mention correct x and y coordinates on the screen for every control used.
This layout form is usually less in use and is not appropriate for UI development because keeping absolute position for every control leads to inflexible User Interface.
UI that is not flexible is difficult to maintain and thus is not commonly used.
TableLayout arranges the content data or information into the set of columns and rows. Rows are defined in XML and columns are automatically determined by Android. This simple task is achieved by defining atleast one column for each element. Thus for example, if a row with three elements and another row with six elements then a layout with three rows and six columns is created.
“android:layout_span” is used to mention that an element consists of more than one column.
It also increases the count for total column, that is; if a row with three elements are defined and each element have android:layout_span=”3″ then total 9 columns will be there in table. By default, Android places every element in the first column of the unused row. User can also mention the column for the element by android:layout_column.
LinearLayout arrange a set of elements on a single line. Vertical or Horizontal attribute can be mentioned in “Android:orientation”.
It can implement mixture of both the vertical and horizontal line values, thus following nested layout schema.Linear layout is mostly nested.
There is much more to learn about Android and to learn a complete mobile application development training course for building Android apps is a great mission. We at TOPS have experienced faculty to provide Android training for live project in Android to students who wish to make their career in mobile development field. Get a complete practical idea of how all the different patterns for Android layouts work for apps and build your own Android apps.