您的位置:首页 > 移动开发 > Android开发

Android: Linear Layout and weight

2014-04-10 16:20 411 查看
使用weight需要记住三点:
子元素的android:layout_width都要设为 “0dp”
父元素的android:weightSum 设为子元素的weight之和(可选项,会默认生成)
子元素的android:layout_weight的设置遵照android:weightSum按比例分配
例子:

<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:weightSum="5">

<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="1" />

<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="3"
android:text="2" />

<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="3" />

</LinearLayout>


结果:



翻译源自:
http://stackoverflow.com/questions/2698817/linear-layout-and-weight-in-android
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: