没有合适的资源?快使用搜索试试~ 我知道了~
Android中的android:layout_weight使用详解
5星 · 超过95%的资源 0 下载量 125 浏览量
2020-09-05
05:02:12
上传
评论
收藏 38KB PDF 举报
温馨提示
试读
1页
layout_weight的作用是设置子空间在LinearLayout的重要度(控件的大小比重)。layout_weight的值越低,则控件越重要,下面为大家介绍下具体的使用方法
资源推荐
资源详情
资源评论
Android中的中的android:layout_weight使用详解使用详解
layout_weight的作用是设置子空间在LinearLayout的重要度(控件的大小比重)。layout_weight的值越低,则
控件越重要,下面为大家介绍下具体的使用方法
在使用LinearLayout的时候,子控件可以设置layout_weight。layout_weight的作用是设置子空间在LinearLayout的重要度(控
件的大小比重)。layout_weight的值越低,则控件越重要。若不设置layout_weight则默认比重为0。
如果在一个LinearLayout里面放置两个Button,Button1和Button2,Button1的layout_weight设置为1,Button2的
layout_weight设置为2,且两个Button的layout_width都设置为fill_parent。
复制代码 代码如下:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Button1"/>
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="2"
android:text="Button2"/>
</LinearLayout>
则Button1占据屏幕宽度的三分之二,而Button2占据三分之一,如下图所示:
如果两个Button的layout_width都设置成wrap_content,则情况刚好相反。Button1占三分之一,Button2占三分之二,如下图
所示:
layout_weight在使用LinearLayout设计复杂的布局时还是挺有用处的,例如,在水平的线性布局中,你要分足够的空间给控件
1,剩下的空间则分配给控件2,则只要设置控件1的layout_width设置为wrap_content,不用设置layout_weight,而在控件2
中,设置layout_width为fill_parent,layout_weight为1即可实现。
weixin_38537689
- 粉丝: 4
- 资源: 905
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
前往页