Android Layouts

Layouts are important because they directly affect the look and feel of application. Technically, a layout is a view that arranges child views added to it. Android comes with a number of built-in layouts, ranging from LinearLayout, which is the easiest to use, to RelativeLayout, which is the most powerful.

Layout Overview
An important Android component, a layout defines the visual structure of your UI components. A layout is a subclass of android.view.ViewGroup, which in turn derives from android.view.View. A ViewGroup is a special view that can contain other views. A layout can be declared in a layout file or added programmatically at runtime.

The following are some of the layouts in Android.

LinearLayout. A layout that aligns its children in the same direction, either horizontally or vertically.

RelativeLayout. A layout that arranges each of its children based on the positions of one or more of its siblings.

FrameLayout. A layout that arranges each of its children based on top of one another.

TableLayout. A layout that organizes its children into rows.

In a majority of cases, a view in a layout must have the layout_width and layout_height attributes so that the layout knows how to size the view. Both layout_width and layout_height attributes may be assigned the value match_parent (to match the parent’s width/height), wrap_content (to match the width/height of its content) or a measurement unit.

The AbsoluteLayout, which offers exact locations for its child views, is deprecated and should not be used. Use RelativeLayout instead.

Leave a Reply

Your email address will not be published. Required fields are marked *