android:weight的使用
android:weight属性能够根据手机高宽按设定比例显示控件
如:
宽度上按比例显示
<LinearLayout
android:layout_marginTop="5dp"
android:orientation="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:orientation="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进阶学习】实现没有标题栏的窗口和全屏显示
- Android之ListView中的分割线
- Android(安卓)studio教程学习笔记4——TextView
- Android:漫画APP开发笔记之ListView中图片按屏幕宽度缩放
- Android中TextVIew一些属性
- Android(安卓)share绘制虚线在手机上显示实线问题
- TextView显示链接
- Android(安卓)HDMI( 三)
- Android(安卓)学习记录-ImageView显示格式