Framelayout, linearlayout, relativelayout

FrameLayout

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中的一个子元素指定一个位置; 后一个子元素将会直接在前一个子元素之上进行覆盖填充,把它们部分或全部挡住

LinearLayout

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.

RelativeLayout

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

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

GridView

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

TableLayout

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

TabLayout

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

via

http://technicalmumbojumbo.wordpress.com/2011/12/08/android-tutorial-series-layout/

http://blog.csdn.net/android_tutor/article/details/4779097

When to Use LinearLayout vs. RelativeLayout

Advertisements

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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

生活在西班牙

自己动手丰衣足食

BlueAsteroid

Just another WordPress.com site

Jing's Blog

Just another WordPress.com site

Start from here......

我的心情魔方

天才遠私廚

希望能做一個分享各種資訊的好地方

语义噪声

西瓜大丸子汤的博客

笑对人生,傲立寰宇

Just another WordPress.com 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

datarazzi

Life through nerd-colored glasses

Luciana Haill

Brainwaves Augmenting Consciousness

槑烎

1,2,∞

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: