layout_width="0dip"或layout_height="0dip"的情況

 Layout 中有寫法如下:

     layout_height="0dip"  或者 layout_width="0dip"   

     這裏的意思是不是用具體的數值來計算高度或者寬度,而是和layout_weight 一起來使用的。經常會有這樣的寫法: 同一個LinearLayout  (假設是橫向的) 中 有幾個view ,但是都不指定其具體的寬度,而是使用 layout_weight 參數來指定這幾個view所佔的比例。每個view所佔的寬度的比例是自己的layout_weight 值和總的layout_weight的總和的比值。

例如:

<LinearLayoutandroid:id="@+id/remove_account_area"

       android:layout_width="match_parent"

       android:layout_height="wrap_content"

       android:orientation="horizontal"

       android:background="@android:drawable/bottom_bar">

        <View

           android:layout_width="0dip"

           android:layout_height="match_parent"

           android:layout_weight="1"/>

        <Buttonandroid:id="@+id/remove_account_button"

           android:layout_width="0dip"

           android:layout_height="wrap_content"

            android:layout_weight="2"

           android:layout_marginTop="5dip"

           android:text="@string/remove_account_label" />

        <View

            android:layout_width="0dip"

           android:layout_height="match_parent"

           android:layout_weight="1"/>

   </LinearLayout>


這幾個View寬度的的比例便是1:2:1


轉自:http://blog.csdn.net/vallay_star/article/details/7013169

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