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. 申请Android Maps API Key,以及出现的错误
  2. Android 错误案例
  3. Android Studio:xxx is not an enclosing class 错误的解决方法
  4. Android中AutoCompleteTextView的特殊使用方法
  5. 如何解决Eclipse开发android程序的编译错误:com/android/dx/comm
  6. Eclipse 开发Android 出现 aapt.exe 应用程序错误,该内存不能为“

随机推荐

  1. 【译文】通过 android:ssp 高效过滤 Andr
  2. Android访问服务器出现W/System.err(9302
  3. Android(安卓)& Chrome
  4. Android(安卓)ANR问题分析
  5. Android七大布局
  6. listview使用小技巧
  7. ROS与Android的通信
  8. java/android 统计文件夹大小及删除文件
  9. Android 登录界面Demo源码
  10. android在代码中为new出的控件设置ID及se