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>
這個功能在實際開發中還是蠻有用的,有很好的適配性。