提高显示布局文件的性能 1 - 优化布局层级
来源:互联网 发布:博客数据库设计 编辑:程序博客网 时间:2024/05/29 18:31
http://blog.csdn.net/kesenhoo/article/details/7378239
Optimizing Layout Hierarchies [优化Layout层级]
- 【Layout是Android程序影响用户体验最关键的一部分。如果布局文件不好会使得程序比较卡。SDK里面包含了一些工具用来帮助我们发现布局文件的性能问题】
- 【这里有一个共同的误区:使用基本的Layout结构是最有效的。但是,每一个添加到系统的组件都需要初始化,进行布局,绘制的过程。比如,使用在LinearLayout里面使用子组件会导致一个过于deep的层级结构。而且内嵌使用包含layout_weight属性的LinearLayout会在绘制时花费昂贵的系统资源,因为每一个子组件都需要被测量两次。在使用ListView与GridView的时候,这个问题显的尤其重要,因为子组件会重复被创建】
这一课我们会学习使用Hierarchy Viewer andLint 来检查并最优化布局文件。
Inspect Your Layout[查看Layout]
Android SDK里面包含了一个叫做Hierarchy Viewer的工具,在程序运行的时候分析布局文件,从而找住性能瓶颈连接上设备,打开Hierarchy Viewer(定位到tools/目录下,直接执行hierarchyviewer的命令,选定需要查看的Process,再点击Load View Hierarchy会显示出当前界面的布局Tree。在每个模块的Traffic light上有三个灯,分别代表了Measure, Layout and Draw三个步骤的性能。
Revise Your Layout [修改你的Layout]
Use Lint [使用Lint]
Lint是一款在ADT 16才出现用来替代layoutopt的新型工具,具有更强大的功能。- Use compound drawables - A
LinearLayout
which contains anImageView
and aTextView
can be more efficiently handled as a compound drawable. - 【使用compound drawables - 一个包含了ImageView与TextView的LinearLayout可以被当作一个compound drawable来处理】
- Merge root frame - If a
FrameLayout
is the root of a layout and does not provide background or padding etc, it can be replaced with a merge tag which is slightly more efficient. - 【使用merge根框架 - 如果FramLayout仅仅是一个纯粹的(没有设置背景,间距等)布局根元素,我们可以使用merge标签来当作根标签】
- Useless leaf - A layout that has no children or no background can often be removed (since it is invisible) for a flatter and more efficient layout hierarchy.
- 【无用的分支 - 如果一个layout并没有任何子组件,那么可以被移除,这样可以提高效率】
- Useless parent - A layout with children that has no siblings, is not a
ScrollView
or a root layout, and does not have a background, can be removed and have its children moved directly into the parent for a flatter and more efficient layout hierarchy. - 【无用的父控件 - 如果一个layout只有子控件,没有兄弟控件,并且不是一个ScrollView或者根节点,而且没有设置背景,那么我们可以移除这个父控件,直接把子控件提升为父控件】
- Deep layouts - Layouts with too much nesting are bad for performance. Consider using flatter layouts such as
RelativeLayout
orGridLayout
to improve performance. The default maximum depth is 10. - 【深层次的layout - 尽量减少内嵌的层级,考虑使用更多平级的组件
RelativeLayout
orGridLayout来提升布局性能,默认最大的深度是10
】
- 提高显示布局文件的性能 1 - 优化布局层级
- 【Android Training - Performance】提高显示布局文件的性能[Lesson 1 - 优化布局层级]
- Android Training - 提升布局文件的性能(Lesson 1 - 优化布局的层级)
- 提高布局文件的显示性能。
- 优化Layout布局层级
- 提高显示布局文件的性能 4 - 提升ListView的性能
- 提高显示布局文件的性能 3 - 按需载入视图(ViewStub的使用方法)
- 【Android Training - Performance】提高显示布局文件的性能[Lesson 2 - 使用include标签重用Layout]
- 提高显示布局文件的性能 2 - 使用include标签重用Layout
- Android提高显示布局文件的性能,使用include标签重用layouts
- [Android 性能优化系列]布局篇之减少你的界面层级
- [Android 性能优化系列]布局篇之减少你的界面层级
- 如何优化你的布局层级结构之RelativeLayout和LinearLayout及FrameLayout性能分析
- 如何优化你的布局层级结构之RelativeLayout和LinearLayout及FrameLayout性能分析
- 如何优化你的布局层级结构之RelativeLayout和LinearLayout及FrameLayout性能分析
- 如何优化你的布局层级结构之RelativeLayout和LinearLayout及FrameLayout性能分析
- 如何优化你的布局层级结构之RelativeLayout和LinearLayout及FrameLayout性能分析
- 使用ViewStub 优化XML布局 提高性能
- Linux mv命令
- 一分钟掌握Spring中bean的生命周期
- extjs class
- C++ 学习书籍
- Error: unterminated string literal
- 提高显示布局文件的性能 1 - 优化布局层级
- Hadoop MR 实现视频拉流框架
- 对CentOS服务器上正使用MRTG进行移机操作
- Linux chown命令
- Git工具连接GitHub(Windows配置篇)
- Oracle RAC 11gR2安装的必要条件
- JS替换空格回车换行符
- vc托管调用c#dll
- Navicat for Mysql 的快捷键综合