Programming and Personal Development

4 useful android layouts for your next mobile app

Android provides layouts for grouping and arranging the widgets like Buttons, labels etc in the UI. Think of them as containers into which the individual widgets/elements and possibly other layouts (with their own set of  child elements) can be poured into and arranged to fit at the desired positions in the UI.

There are several layouts that come with android-sdk. Depending on your needs you might use one more than the other.

  • Linear Layout : This is the simplest and probably the most common UI layout.  It simply arranges the elements in the input order, one after the other . You can also choose the orientation for the layout as either vertical or horizontal. For horizontal orientation, the elements are rendered from left to right and for vertical orientation, they are rendered from top to bottom.  The default  orientation is horizontal. In addition you can specify properties to control the space between the individual elements, their alignments, their relative weights etc.
  • Table Layout : The android table layout is useful for displaying data as a set of rows and columns. It contains a number of “TableRow” elements each of which represents a row in the table. The Table row contains other elements such buttons, images etc making up the columns within the row.  The row with the most columns decides the number of columns for the table.  In addition the table layout provides properties to automatically stretch, shrink and collapse specific columns.
  • Relative Layout: You can use the android relative layout to arrange the components relative to one another. For example,  if you have three elements A, B & C,  then you can say things like A lies to the left of B or B lies at the top C or align the top of element A with its parent container and so on. Since the elements are positioned relative to one another, there is  a need to refer them by ID .  You can do this by giving a android:id for each element in the layout.xml file.
  • Frame Layout:  This is a very simple layout that positions the elements at the top-left corner. Subsequent elements are placed on top of the previous elements similar to a stack of cards.

 

 

Web Analytics