使用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如何让TextView子元素随着父元素的背景变化而改变字体颜
  2. android开发中常用的五大布局
  3. Android(java)学习笔记106:Android(安卓)XML解析
  4. android 相对定位布局方向
  5. android layout属性介绍
  6. android 布局属性
  7. RelativeLayout属性
  8. 【转】android manifest.xml中元素含义
  9. layout布局属性

随机推荐

  1. Elasticsearch 索引的映射配置详解
  2. 注册中心 Eureka 源码解析 —— 项目结构
  3. 注册中心 Eureka 源码解析 —— Eureka-C
  4. 分布式事务 TCC-Transaction 源码分析 —
  5. Spring Cloud Feign的两种使用姿势
  6. 分布式事务 TCC-Transaction 源码分析 —
  7. 注册中心 Eureka 源码解析 —— Eureka-S
  8. 分布式事务 TCC-Transaction 源码分析 —
  9. 注册中心 Eureka 源码解析 —— Eureka-C
  10. 网关 Spring-Cloud-Gateway 源码解析 —