美文网首页Android Utils
Android UI 布局 layout_weight 参数

Android UI 布局 layout_weight 参数

作者: 几千里也 | 来源:发表于2015-04-16 11:04 被阅读25次

先看个简单的例子:

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:gravity="center"
        android:weightSum="1">

        <Button android:text="@string/hello_world"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="0.5"/>

    </LinearLayout>
图 1 图 2

要注意的事情:

  1. 只有在 Linearlayout 中 layout_weight 属性才有效。
  2. 一旦 View 设置了 layout_weight 属性,那么该 View 的宽度等于(layout_width 的值 + 剩余空间的占比)!

相关文章

网友评论

    本文标题:Android UI 布局 layout_weight 参数

    本文链接:https://www.haomeiwen.com/subject/nqbsfttx.html