[转载]Android的UI布局总览

[转载]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

它的子类:

Known Direct Subclasses

AppWidgetHostView, CalendarView, DatePicker, GestureOverlayView, HorizontalScrollView, MediaController, ScrollView, TabHost, TimePicker, ViewAnimator

Known Indirect Subclasses

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布局中嵌套而成的

继承关系如下

java.lang.Object

android.view.View

android.view.ViewGroup

android.widget.LinearLayout

他的子类有:

Known Direct Subclasses

NumberPicker, RadioGroup, SearchView, TabWidget, TableLayout, TableRow, ZoomControls

四。AbsoluteLayout简介

AbsoluteLayout绝对布局。指定了子元素的x/y坐标值,并显示在屏幕上。该布局没有屏幕边框,允许元素之间互相重叠,在实际中不提倡使用这种布局,因为固定了位置,所以在屏幕旋转式会有不完整。

java.lang.Object

继承关系如下
android.view.View
android.view.ViewGroup
android.widget.AbsoluteLayout

他的子类有:

Known Direct Subclasses

WebView

*************This class is deprecated.
Use FrameLayout, RelativeLayoutor 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.

赞(0) 打赏
分享到: 更多 (0)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏