天天看點

Android學習筆記(8):ViewGroup類

a viewgroup is a special view that can contain other views (called children.) 

the view group is the base class for layouts and views containers. 

this class also defines the viewgroup.layoutparams class which serves as the base class for layouts parameters.

viewgroup是view的一個子類,本身是一個抽象類,ui控件都是由view和viewgroup派生而來的,其中viewgroup的子類通常作為容器,或者說是布局管理器。

容器内子元件的分布依賴viewgroup.layoutparams和viewgroup.marginlayoutparams,這是viewgroup的兩個内部類。

viewgroup.layoutparams所支援的xml屬性:

android:layout_height——指定該子元件的布局高度

android:layout_width——指定該子元件的布局寬度

這兩個屬性的可選屬性值如下:

(1). fill_parent——子元件寬度、高度與父容器相同

(2). match_parent——子元件寬度、高度與父容器相同(與上相同,推薦使用)

(3). wrap_content——子元件的大小剛好能包裹它的内容

android元件的大小除了受實際寬度、高度的控制,還受其布局寬度和高度控制,且布局寬度、高度其主要作用。

viewgroup.marginlayoutparams所支援的xml屬性:

attribute name

related method

description

android:layout_marginbottom

setmargins(int,int,int,int)

設定該子元件下邊的頁邊距

android:layout_marginend

setmarginend(int)

設定該子元件距離終邊的頁邊距

android:layout_marginleft

設定該子元件左邊的頁邊距

android:layout_marginright

設定該子元件右邊的頁邊距

android:layout_marginstart

setmarginstart(int)

設定該子元件距離起始邊的頁邊距

android:layout_margintop

設定該子元件上邊的頁邊距