Android的UI布局總覽
android布局的目的是為了實現不同屏幕比例適配而設計的,有五種布局類:FrameLayout、LinearLayout、AbsoluteLayout、RelativeLayout和TableLayout。五大布局類的繼承關系如下(以FrameLayout為例):
java.lang.Object
android.view.View
android.view.ViewGroup
android.widget.FrameLayout
一。FrameLayout簡介
FrameLayout框架布局,在此布局下的所有對象都固定在屏幕的做上角顯示,不能指定位置。最大的特點是可以添加多個子類通過android:layout_gravity
來指定子類視圖的位置。同一位置的子類視圖處于層疊狀,最上面的子類視圖是最后添加的子類視圖。
繼承關系如下:
java.lang.Object
android.view.View
android.view.ViewGroup
android.widget.FrameLayout
它的子類:
AppWidgetHostView, CalendarView, DatePicker, GestureOverlayView, HorizontalScrollView, MediaController, ScrollView, TabHost, TimePicker, ViewAnimator
ImageSwitcher, TextSwitcher, ViewFlipper, ViewSwitcher
二。RelativeLayout簡介
RelativeLayout相對布局,允許子元素指定他們相對于其他元素或者父元素的位置(通過ID指定),可以左右對齊,上下對齊,指定屏幕位置等形式來排列元素。
繼承關系如下:
java.lang.Object
android.view.View
android.view.ViewGroup
android.widget.RelativeLayout
常用屬性介紹:
android:layout_above
Positions the bottom edge of this view above the given anchor view ID.
android:layout_alignBaseline
Positions the baseline of this view on the baseline of the given anchor view ID.
android:layout_alignBottom
Makes the bottom edge of this view match the bottom edge of the given anchor view ID.
android:layout_alignLeft
Makes the left edge of this view match the left edge of the given anchor view ID.
android:layout_alignParentBottom
If true, makes the bottom edge of this view match the bottom edge of the parent.
android:layout_alignParentLeft
If true, makes the left edge of this view match the left edge of the parent.
android:layout_alignParentRight
If true, makes the right edge of this view match the right edge of the parent.
android:layout_alignParentTop
If true, makes the top edge of this view match the top edge of the parent.
android:layout_alignRight
Makes the right edge of this view match the right edge of the given anchor view ID.
android:layout_alignTop
Makes the top edge of this view match the top edge of the given anchor view ID.
android:layout_alignWithParentIfMissing
If set to true, the parent will be used as the anchor when the anchor cannot be be found for layout_toLeftOf, layout_toRightOf, etc.
android:layout_below
Positions the top edge of this view below the given anchor view ID.
android:layout_centerHorizontal
If true, centers this child horizontally within its parent.
android:layout_centerInParent
If true, centers this child horizontally and vertically within its parent.
android:layout_centerVertical
If true, centers this child vertically within its parent.
android:layout_toLeftOf
Positions the right edge of this view to the left of the given anchor view ID.
android:layout_toRightOf
Positions the left edge of this view to the right of the given anchor view ID.
三。LinearLayout簡介
LinearLayout線性布局,線性布局是所有布局中最常用的,他可以讓其中的子元素按垂直或水平的方式排列(通過排列的方向設置),通常復雜的布局都是在LinearLayout布局中嵌套而成的。
繼承關系如下:
android.widget.LinearLayout
他的子類有:
NumberPicker, RadioGroup, SearchView, TabWidget, TableLayout, TableRow, ZoomControls
四。AbsoluteLayout簡介
AbsoluteLayout絕對布局。指定了子元素的x/y坐標值,并顯示在屏幕上。該布局沒有屏幕邊框,允許元素之間互相重疊,在實際中不提倡使用這種布局,因為固定了位置,所以在屏幕旋轉式會有不完整。
繼承關系如下:
android.view.View
android.view.ViewGroup
android.widget.AbsoluteLayout
他的子類有:
*************This class is deprecated.
Use FrameLayout
, RelativeLayout
or a custom layout instead.
五。TableLayout簡介
TableLayout表格布局。將子元素的位置分配到行或列中,TableLayout布局有許多TableRow(行)組成,但沒有列的概念,列是又行中的控件數目來決定的,TableLayout也是常有布局。TableLayout不會顯示行、列、單元格的邊框線。
繼承關系如下:
java.lang.Object
android.view.View
android.view.ViewGroup
android.widget.LinearLayout
android.widget.TableLayout
他的子類有:
android:collapseColumns
setColumnCollapsed(int,boolean)
The zero-based index of the columns to collapse.
android:shrinkColumns
setShrinkAllColumns(boolean)
The zero-based index of the columns to shrink.
android:stretchColumns
setStretchAllColumns(boolean)
The zero-based index of the columns to stretch.
轉自:http://www.cnblogs.com/zhxiang/archive/2012/01/03/2311311.html