weight的正确使用方法:

先设置android:layout_width="0dp" 或者android:layout_height="0dp"

然后再去调配权重,而此时的weight也非常好理解: weight就是比重。

weight的错误使用方法:

android:layout_width="match_parent"

android:layout_width="wrap_content"

两种情况下该如何设置weight. 因为这样设置根本就是错误的用法.

下面是来自SDK的一句话:In order to improve the layout efficiency when you specify the weight, you should change the width of theEditTextto be zero (0dp). Setting the width to zero improves layout performance because using"wrap_content"as the width requires the system to calculate a width that is ultimately irrelevant because the weight value requires another width calculation to fill the remaining space.它的大致意思就是说: 我们如果在某个方向上使用了weight ,那么我们必须在对应的方向上将width设置为0dp. 它告诉了我们设置为0dp是因为使用weight,系统是采用了另外一套计算占用空间大小的算法的.(the weight value requires another width calculation to fill the remaining space.)

更多相关文章

  1. LinearLayout 内部 挂件 居中
  2. Android——新手指引 指定View高光显示自定义控件
  3. AndroidManifest.xml的Service元素 android:process设置
  4. android创建桌面快捷方式(启动目标非项目的启动页)
  5. Android(安卓)Selector Shape使用详解
  6. Android之背景图片设置为重复而不是默认的拉伸
  7. Android(安卓)GridView 通过seletor 设置状态和默认状态
  8. 申请Android(安卓)Maps API Key,以及出现的错误
  9. Android中贪吃蛇游戏的学习(三)

随机推荐

  1. 【Android(安卓)界面效果8】Android中的
  2. 【.9.img】Android设计中的.9.png
  3. 百度云推送、极光推送等云推送服务搜罗点
  4. android studio引入最新版银联支付功能
  5. android事件分发(二)
  6. Android(安卓)添加新的键值,自定义按键
  7. Windows phone开发初体验之(四)-处理Wind
  8. Android的国际化语言适配(系统语言适配+A
  9. android 线程消息处理【之消息处理中再处
  10. Android(安卓)调试桥|adb命令卸载系统软