layout_weight的意义在于原有面积+剩下的部分 例如添加代码如下 android:id="@+id/btn_a" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/btn_a" android:layout_weight="1" /> android:id="@+id/btn_b" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="2" android:text="@string/btn_b"/> android:id="@+id/btn_c" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/btn_c" android:layout_weight="2" /> 这时在显示时就会按照1:2:2的面积显示 但是这是首先设置的height为自适应 假如把height设置为fill_parent就会出现如下情况 layout_weight的意义" title="android游戏开发课程layout_weight的意义"> 出现这种状况是因为三个Button的layout_height全部设为fill_parent 这其实与weight的原理有关,本来整个屏幕可以认为是1,但3个就需要3 可想而知剩下为1-3=-2 button1就变成了1(本来的fill_parent)+-2*1/5(剩下的)=3/5 button2 1-2/5 3 1-2/5 相当于3:1:1 也就是如图情况

更多相关文章

  1. android手动拖动滚动条快速滑动
  2. 元素可指定如下常用属性
  3. Android(安卓)android:gravity属性介绍及效果图
  4. [转]Android(安卓)源代码结构
  5. android 带文字的ImageButton
  6. centos下安装adb环境
  7. 解决Could not find manifest-merger.jar问题
  8. Android下修改ImageButton样式
  9. android手动拖动滚动条快速滑动

随机推荐

  1. 2020年Android发展趋势年度总结
  2. Android(安卓)TextView属性大全
  3. Android(安卓)中intent传递序列化信息(传
  4. Android(安卓)文件的保存与读取之SDCard(S
  5. android内存泄露
  6. Android中的消息机制
  7. android getResources的作用
  8. ❤️【Android精进之路-04】Android核心组
  9. 分享Android(安卓)KTX + Kotlin协程 组合
  10. android ndk 开发