|
android:weight属性能够根据手机高宽按设定比例显示控件
如:
宽度上按比例显示
<LinearLayout
android:layout_marginTop="5dp" android rientation="horizontal"android:layout_width="fill_parent"----------------让其满宽 android:layout_height="wrap_content"> <Button android:id="@+id/first_sex1_4" android:layout_marginLeft="15dp" android:layout_width="0dp"---------设置0dp,让宽度由比例生成 android:layout_weight="1" android:layout_height="50dp"/> <Button android:id="@+id/first_sex1_5" android:layout_marginLeft="5dp" android:layout_width="0dp" android:layout_weight="3" android:layout_height="50dp"/> </LinearLayout>
注意现在android:layout_width="0dp"
最终3个按钮显示的宽度比例为1:3,和weight一样,值大的权高,显示宽度大
然而如果把 android:layout_width="fill_parent"
<LinearLayout
android:layout_marginTop="5dp" android rientation="horizontal"android:layout_width="fill_parent"----------------让其满宽 android:layout_height="wrap_content"> <Button android:id="@+id/first_sex1_4" android:layout_marginLeft="15dp" android:layout_width="fill_parent"---------设置fill_parent,让宽度由比例生成 android:layout_weight="1" android:layout_height="50dp"/> <Button android:id="@+id/first_sex1_5" android:layout_marginLeft="5dp" android:layout_width="fill_parent" android:layout_weight="3" android:layout_height="50dp"/> </LinearLayout>
注意现在android:layout_width="fill_parent"
最终3个按钮显示的宽度比例为3:1,和weight相反,值大的权低,显示宽度小
|
android:weight的使用
最新推荐文章于 2021-05-26 21:28:46 发布
本文详细介绍了在Android布局中使用weight属性实现控件按比例显示的方法,并通过实例展示了如何调整宽度比例来控制控件的显示效果。通过将weight属性应用于不同宽度设置,可以灵活地调整控件在屏幕上的布局比例,实现美观且响应式的UI设计。
rientation="horizontal"
4169

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



