Android 基礎——LinearLayout

一、LinearLayout

              <LinearLayout
             android:layout_width="match_parent"
             android:layout_height="wrap_content"
             android:layout_marginRight="10px"
             android:gravity="right">
             <Button
                 android:id="@+id/exit"
                 android:layout_width="wrap_content"
                 android:layout_height="wrap_content"
                 android:text="exit" />
         </LinearLayout>

線性佈局中,有 4 個及其重要的參數,直接決定元素的佈局和位置,這四個參數是:

android:layout_gravity ( 是本元素相對於父元素的重力方向 )   

android:gravity (是本元素所有子元素的重力方向)   

android:orientation (線性佈局以列或行來顯示內部子元素)   

android:layout_weight (線性佈局內子元素對未佔用空間【水平或垂直】分配權重值,其值越小,權重越大。                               

前提是子元素 設置了 android:layout_width = "fill_parent" 屬性(水平方向),或 android:layout_height = "fill_parent" 屬性(垂直方向),如果某個子元素的 android:layout_width = "wrap_content" 或 android:layout_height =" wrap_content” ,    則 android:layout_weight 的設置值 對該方向上空間的分配剛好相反。

發佈了7 篇原創文章 · 獲贊 7 · 訪問量 4萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章