Logo Icon Logo
A Crowd-sourced Cookbook on Writing Great Android Apps
GitHub logo Twitter logo OReilly Book Cover Art
Choosing a Layout Manager (ViewGroup) and Arranging ComponentsBack to Android Cookbook Home | Up to Chapter: Graphical User Interface

Author: Ian Darwin ('idarwin')
In Published Edition? No
FormatLanguage: WikiFormat

Choosing a Layout Manager (ViewGroup) and Arranging Components


You want to know how to arrange your GUI components within your view.


There are many layout managers or ViewGroups available. The table below should help you get a handle on which one(s) to use.


As in the case of JavaSE and most other GUI packages, there are multiple components you can use to control the layout of individual GUI components. JavaSE's AWT and Swing provide two classes that work together, Container and LayoutManager. A Container *has a* LayoutManager instance to perform layout calculations on its behalf. Android, having been conceived for smaller devices, combines these two functions into a single class, android.view.ViewGroup. There are many subclasses of ViewGroup intended for you to use. While LinearLayout is the best-known, there are many others. There are also some subclasses that are not intended for use as arbitrary layout managers, such as the drop-down-like Spinner (see 3100).

Name Basic idea See Also
AbsoluteLayout Absolute positioning, almost never the right choice!
FrameLayout Multiple Views in a stack
GridLayout Equal-sized Views in rows and columns
LinearLayout Views in a row or column
RelativeLayout Complex layouts, like HTML tables; more efficient than nesting
TableLayout A set of rows each with some number of columns 2106
TabHost Tabbed view 897
SlidingDrawer Vertical divide of the screen 2144
ViewPager Let user flip left and right through pages of data 4483

See Also