Android UI 布局 layout_weight 参数

先看个简单的例子:

    <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 的值 + 剩余空间的占比)!
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容