您现在的位置:主页 > 技术中心 > 编程开发 > 移动开发 > Android

Android属性系列之layout_weight

来源:未知 责任编辑:责任编辑 发表时间:2015-09-17 09:44 点击:

对自己现在所了解的layout_weight属性进行记录,不求全面,只求正确!

layout_weight意为"权重",我的理解就是给组件设置一个显示大小的比例。
layout_weight设置一个值,会出现两种情况。
第一种:当组件的“layout_width”属性为“fill_parent”时,值越小,组件越大。
第二种:当组件的“layout_width”属性为“wrap_content”时,值越大,组件越大。

第一种情况:
Xml代码 
<LinearLayout  
    android:layout_weight="1" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:orientation="horizontal" 
    android:layout_marginLeft="10dp" 
    android:layout_marginRight="10dp" 

    <Button  
        android:id="@+id/btn_save" 
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content" 
        android:layout_weight="1" 
        android:text="保存" 
    /> 
     
    <Button  
        android:id="@+id/btn_return" 
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content" 
        android:layout_weight="4" 
        android:text="返回" 
    /> 
</LinearLayout> 

在这里"保存"按钮的Layout_weight=1,"返回"按钮的Layout_weight=4,layout_width="fill_parent"时, 运行效果为:
 

第二种情况:
Xml代码 
<LinearLayout  
    android:layout_weight="1" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:orientation="horizontal" 
    android:layout_marginLeft="10dp" 
    android:layout_marginRight="10dp" 

    <Button  
        android:id="@+id/btn_save" 

发表评论
请自觉遵守互联网相关的政策法规,严禁发布色情、暴力、反动的言论。
评价:
表情:
用户名: 验证码:点击我更换图片

推荐热点

  • Android 完全退出程序
  • 原创:Android应用开发-Andorid歌词秀,含源码
  • android 屏幕保护
  • Android手机软件汉化教程---第四课 dex文件汉化
  • 众多Android 开源项目推荐,给力工作给力学习
  • Android Audio代码分析4
  • Android得到已安装的应用程序信息!
  • MIUI:10个亮点及5处不足
  • Android成长的幕后推手:工程师鲁宾
?? - ?? - ÝřŝžľŘÝź - TAGąęÇŠ - RSSśŠÔÄ - ??
Copyright © 2004-2024 上海卓卓网络科技有限公司