微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

浅析layout_weight属性,gravity属性,layout_gravity属性

参考:http://developer.android.com/guide/topics/ui/layout/linear.html

layout_weight属性 <基于LinearLayout 下的view>

  • 布局权重,意味这个view在当前布局中占据多大空间(比重)
  • 拥有更大weight值的view被允许扩展填充满parent view.(填满剩余空间)
  • 所有view认weight值为0
    例子:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical">

    <EditText  android:id="@+id/one" android:layout_width="match_parent" android:layout_height="wrap_content" android:hint="one" />

    <EditText  android:id="@+id/two" android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1" android:hint="two" />

</LinearLayout>

在上述xml中。two的layout_height值设置为任意值都不会影响布局结果,一般我们设置为0dp。

gravity属性

  • 指在当前view大小内,内容的位置。如TextView中,EditText中的文本的位置。(重心)

layout_gravity属性

  • 指当前view在parent view中的位置

注意:

当我们把layout_width 或 layout_height 的值设置为负值时,系统会按照 warp_content 处理。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


php输出xml格式字符串
J2ME Mobile 3D入门教程系列文章之一
XML轻松学习手册
XML入门的常见问题(一)
XML入门的常见问题(三)
XML轻松学习手册(2)XML概念
xml文件介绍及使用
xml编程(一)-xml语法
XML文件结构和基本语法
第2章 包装类