使用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

更多相关文章

  1. 【转】android manifest.xml中元素含义
  2. AndroidManifest.xml的Service元素 android:process设置
  3. android manifest.xml中元素含义
  4. Android 元素居中
  5. Android如何让TextView子元素随着父元素的背景变化而改变字体颜
  6. 元素可指定如下常用属性
  7. 自定义动画(animation)时set中的各元素效果

随机推荐

  1. Android(安卓)6.0下报错: UnsatisfiedLin
  2. 使用ActivityGroup来切换Activity和Layou
  3. Android(安卓)- 预装(push) lib64中so文
  4. Ubuntu下安装Android反编译工具apktool和
  5. Android中SimpleAdapter,ArrayAdapter和Ba
  6. Android(安卓)OOM以及GC的一些建议
  7. android activity的4种启动模式
  8. android触摸屏事件手势操作滑动处理
  9. Android(安卓)Studio打包时如何将版本号
  10. Android--隐藏状态栏图标