Android中RelativeLayout和LinearLayout性能分析
来源:互联网 发布:linux chmod nobody 编辑:程序博客网 时间:2024/05/21 01:29
参考> http://www.jianshu.com/p/8a7d059da746
先说结论
- RelativeLayout与LinearLayout,到底谁的性能更高,以前面试经常会被问到的问题:
- 1.在不影响层级深度的情况下,使用LinearLayout而不是RelativeLayout。
2.因为RelativeLayout会让子View调用2次onMeasure,LinearLayout只会让子View调用1次onMeasure (在有weight时,也会调用子View2次onMeasure)
简单布局的绘制时间对比
LinearLayout
Measure:0.738ms
Layout:0.176ms
draw:7.655ms
RelativeLayout
Measure:2.280ms
Layout:0.153ms
draw:7.696ms
layout和draw的过程两者相差无几,考虑到误差的问题,几乎可以认为两者不分伯仲,关键是Measure的过程RelativeLayout却比LinearLayout慢了一大截
具体的绘制过程可以看下源码,顶部原文链接中有
总结起来原因就是:
1.RelativeLayout中子View的排列方式是基于彼此的依赖关系,有可能是上下,有可能是左右,这两个方向需要分别测量。
2.LinearLayout的measure就简单明了的多了,先判断线性规则,然后执行对应方向上的测量一次就好。
3.如果使用weight属性,LinearLayout会避开设置过weight属性的view做第一次measure,完了再对设置过weight属性的view做第二次measure。由此可见,weight属性对性能是有影响的.
0 0
- Android中RelativeLayout和LinearLayout性能分析
- Android中RelativeLayout和LinearLayout性能分析
- Android中RelativeLayout和LinearLayout性能分析
- Android中RelativeLayout和LinearLayout性能分析
- Android中RelativeLayout和LinearLayout性能分析
- Android中RelativeLayout和LinearLayout性能分析
- android中RelativeLayout和LinearLayout性能分析
- Android中RelativeLayout和LinearLayout性能分析
- Android中RelativeLayout和LinearLayout性能分析
- Android中RelativeLayout和LinearLayout性能分析
- Android中RelativeLayout和LinearLayout性能分析
- Android RelativeLayout和LinearLayout性能分析
- Android RelativeLayout和LinearLayout性能分析
- 【Android】RelativeLayout和LinearLayout性能分析
- Android中RelativeLayout与LinearLayout的性能分析
- Android中LinearLayout和RelativeLayout使用详解
- Android中relativeLayout和LinearLayout详解
- 【Android】 LinearLayout和RelativeLayout
- Android练手小项目:仿看房app
- Okhttp3表单上传数据到服务器使用指南
- sicily Highways prim算法与kruskal算法详解
- Mac 运行sh文件,也就是传说中的shell脚本
- Java经典兔子问题
- Android中RelativeLayout和LinearLayout性能分析
- activity的启动模式
- 331. Verify Preorder Serialization of a Binary Tree
- cocos2d-x-3.12 打包apk出现 XXX如 libfreetype.a exists or that its path is correct 执行命令出错,返回值:2。
- 视觉项目中评估图像质量的关键指标
- Java通过Class的对象来获取泛型的class示例
- 计算机权限 用户组 system everyone 深入理解
- 统计基本知识-1
- 【LeetCode】 003. Longest Substring Without Repeating Characters