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>
这个功能在实际开发中还是蛮有用的,有很好的适配性。
本文介绍如何在Android开发中使用weightSum和layout_weight属性来实现按钮在横竖屏下均占屏幕50%的效果,并提供实际应用案例和源代码。适用于快速适应不同设备尺寸的需求。
3339

被折叠的 条评论
为什么被折叠?



