android 小技巧,不断更新中

                    android 小技巧,不断更新中

1.weightSum属性和layout_weight 结合使用

android 小技巧,不断更新中_第1张图片

实现上图的效果,不管横竖屏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>

这个功能在实际开发中还是蛮有用的,有很好的适配性。

你可能感兴趣的:(android)