android 小技巧,不斷更新中

                    android 小技巧,不斷更新中

1.weightSum屬性和layout_weight 結合使用

這裏寫圖片描述
這裏寫圖片描述
實現上圖的效果,不管橫豎屏button 都佔屏幕的50%的

 <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="#cdcdcd"
        android:gravity="center"
        android:weightSum="1">

        <Button
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="0.5"
            android:text="50%" />  <!--還可以試下80%,都有效果的-->
    </LinearLayout>

這個功能在實際開發中還是蠻有用的,有很好的適配性。

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