[关闭]
@ZeroGeek 2015-08-27T04:27:39.000000Z 字数 939 阅读 678

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

android


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

layout_weight属性 <基于LinearLayout 下的view>

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3. android:layout_width="match_parent"
  4. android:layout_height="match_parent"
  5. android:orientation="vertical">
  6. <EditText
  7. android:id="@+id/one"
  8. android:layout_width="match_parent"
  9. android:layout_height="wrap_content"
  10. android:hint="one" />
  11. <EditText
  12. android:id="@+id/two"
  13. android:layout_width="match_parent"
  14. android:layout_height="0dp"
  15. android:layout_weight="1"
  16. android:hint="two" />
  17. </LinearLayout>

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

gravity属性

layout_gravity属性

注意:

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

添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注