Framelayout, linearlayout, relativelayout


The FrameLayout is the simplest of all layouts. It is designed to contain and display only one UI element. Addition of multiple UI elements will just cause the subsequent elements to overlay above the previous element(s).

所有的子元素将会固定在屏幕的左上角;不能为FrameLayout中的一个子元素指定一个位置; 后一个子元素将会直接在前一个子元素之上进行覆盖填充,把它们部分或全部挡住


This layout container lays out its children aligned to a particular orientation either horizontal or vertical.

The developer needs to define the orientation and the children components are laid out horizontally one besides the other or vertically one below the other.

以你为它设置的垂直或水平的属性值,来排列所有的子元素。所有的子元素都被堆放在其它元素之后,因此一个垂直列表的每一行只会有 一个元素,而不管他们有多宽,而一个水平列表将会只有一个行高(高度为最高子元素的高度加上边框高度)

LinearLayout保持子元素之间的间隔以 及互相对齐——相对一个元素的右对齐、中间对齐或者左对齐。

Linear Layout Example

  • android:gravity – This attribute defines the orientation of text message vis-a-vis the TextView layout. For our example we have provided left aligned orientation.
  • android:layout_gravity – This attribute defines the orientation of the TextView component. Note the layout_gravity takes care of the TextView component orientation, while the gravity attribute takes care of TextView’s text content’s orientation, a vital difference.
  • android:layout_marginLeftbandroid:layout_marginRight,
    android:layout_marginTopandroid:layout_marginBottom – These attributes determine the left, right, top and bottom margin settings for the TextView component. The units are same as the ones defined for width or height.


The RelativeLayout arranges its child components based on component’s layout positioning definition relative to one another. Each component can be laid out above, below, to the left or right of another component. A combination of positional rules such as right of X component and below Y component can also be applied.

允许子元素指定他们相对于其它元素或父元素的位置(通过ID 指定)。因此,可以以右对齐,或上下,或置于屏幕中央的形式来 排列两个元素。如果第一个元素在屏幕的中央,那么相对于这个元素的其它元素将以屏幕中央的相对位置来排列。

Relative Layout Example

AbsoluteLayout: not recommended

可以让子元素指定准确的x/y坐标值,并显示在屏幕上。(0, 0)为左上角,当向下或向右移动时,坐标值将变大。AbsoluteLayout 没有页边框,允许元素之间互相重叠(尽管不推荐)。



ListView displays a list of scrollable items which the user can select. Typically the selection is used to trigger some subsequent processs or activity.

ListView Example


The ListView displays a scrollable single column list. GridView on the other hand displays a scrollable grid of m columns and n rows. ListView is one dimensional, GridView are two dimensional. Like the ListView, the declarative portion of GridView is minimal.

GridView Example


The TableLayout lays out its consituents into rows and columns. The layout consists of number of TableRow components, each containing one or more Android UI components.

Table Layout Example


There are applications which need the tabs. Individual tab page logically groups together data. Android implements this using the TabActivity. However do note that the class TabActivity has been deprecated in the favor of Fragments.

Tabs Layout Example


When to Use LinearLayout vs. RelativeLayout


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s




Just another site

Jing's Blog

Just another site

Start from here......







Just another site

Where On Earth Is Waldo?

A Project By Melanie Coles

the Serious Computer Vision Blog

A blog about computer vision and serious stuff

Cauthy's Blog

paper review...

Cornell Computer Vision Seminar Blog

Blog for CS 7670 - Special Topics in Computer Vision


Life through nerd-colored glasses

Luciana Haill

Brainwaves Augmenting Consciousness



Dr Paul Tennent

and the university of nottingham

turn off the lights, please

A bunch of random, thinned and stateless thoughts around the Web

%d bloggers like this: