Android學習筆記_5種常用佈局的常用屬性

Android 5種常用佈局的常用屬性

一.LinearLayout 線性佈局

android:orientation="vertical"      設置線性佈局方向,表示豎直方式對齊

android:layout_width="fill_parent"    定義當前視圖在屏幕上 可以消費的寬度

android:layout_heigh="wrap_content"   定義當前視圖在屏幕上 可以消費的高度

android:gravity      對齊方式.對元素本身說的,元素本身的文本顯示在什麼地方靠着換個屬性設置,不過不設置默認是在左側的

android:layout_weight     所有的視圖都有一個layout_weight值,默認爲零,意思是需要顯示多大的視圖就佔據多大的屏幕空間

二.AbsoluteLayout絕對佈局

三.FrameLayout框架佈局

四.RelativeLayout相對佈局

(1)定位與組件的上下左右

android:layout_below="@id/.."
android:layout_above="@id/"
android:layout_toLeftOf="@id/"
android:layout_toRightOf="@id/"
(2)定位與組件的邊緣對齊
android:layout_alignLeft="@id/"
android:layout_alignRight="@id/"
android:layout_alignTop="@id/"
android:layout_alignBottom="@id/"
(3)定位與父組件的邊緣對齊
android:layout_alignParentTop="true"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
(4)與整個屏幕的關係
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_centerInParent="true"
(5)組件間的距離
android:layout_marginTop="5dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_marginBottom="5dp"
android:layout_margin="5dp"
 

五.TableLayout表格佈局           

類似於Swing中的GridLayout;
表格佈局的每行用<TabRow>括起來;
在<TableLayout>中可以定義如下屬性:

(1)android:shrinkColumns="1" 表明第2個控件如果裏面的內容過多,會收縮,擴展到第二行,而不是延伸;
(2)android:stretchColumns="2" 如果有空白,第3個控件填充;
(3)android:collapseColumns="0" 隱藏指定的列
在控件中設置:
(1)android:layout_column="2" 將此控件放在第3個位置;
(2)android:layout_span="2" 此控件佔據2個單元位置;

水平線

<view
   android:layout_height="2dp"
   android:backgroup="#FF9090"/>


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章