Android tips tool 发现的性能问题(转载翻译)
先翻译刚好在研究到的一段,其余的无限期待续。
1.ObsoleteLayoutParam不起作用的标签
Invalid layout param in a LinearLayout: layout_centerVertical
Invalid layout param in a ScrollView: layout_weight
Issue: Looks for layout params that are not valid for the given parent layout
Id: ObsoleteLayoutParam
The given layout_param is not defined for the given layout, meaning it has no effect. This usually happens when you change the parent layout or move view code around without updating the layout params. This will cause useless attribute processing at runtime, and is misleading for others reading the layout so the parameter should be removed.
2.HandlerLeak 非静态的内部类Handler
This Handler class should be static or leaks might occur (com.borqs.appinstaller.AppMoveFragment.LoadAppHandler)
Issue: Ensures that Handler classes do not hold on to a reference to an outer class
Id: HandlerLeak
In Android, Handler classes should be static or leaks might occur. Messages enqueued on the application thread's MessageQueue also retain their target Handler. If the Handler is an inner class, its outer class will be retained as well. To avoid leaking the outer class, declare the Handler as a static nested class with a WeakReference to its outer class.
3.FloatMath 有时候Android有更好的API实现相比Java
Use android.util.FloatMath#ceil() instead of java.lang.Math#ceil to avoid argument float to double conversion
Issue: Suggests replacing java.lang.Math calls with android.util.FloatMath to avoid conversions
Id: FloatMath
On modern hardware, "double" is just as fast as "float" though of course it takes more memory. However, if you are using floats and you need to compute the sine, cosine or square root, then it is better to use the android.util.FloatMath class instead of java.lang.Math since you can call methods written to operate on floats, so you avoid conversions back and forth to double.
http://developer.android.com/guide/practices/design/performance.html#avoidfloat
4.InefficientWeight
Use a layout_width/layout_height of 0dip instead of wrap_content for better performance
Issue: Looks for inefficient weight declarations in LinearLayouts
Id: InefficientWeight
When only a single widget in a LinearLayout defines a weight, it is more efficient to assign a width/height of 0dp to it since it will absorb all the remaining space anyway. With a declared width/height of 0dp it does not have to measure its own size first.
当在一个LinearLayout布局中仅包含一个定义weight属性的view控件时,直接指定0dp到其width或height属性更高效,因为在初始化时不再需要测量这个view控件的尺寸,反正到最后它都会霸占所有剩余空间的了。
* 注:weight属性仅应用于控件并排排列共用的空间方向,如vertical方向LinearLayout中子控件的height,此时对width无效。
5.NestedWeights
Nested weights are bad for performance
Issue: Looks for nested layout weights, which are costly
Id: NestedWeights
Layout weights require a widget to be measured twice. When a LinearLayout with non-zero weights is nested inside another LinearLayout with non-zero weights, then the number of measurements increase exponentially.
6.UnusedResources
The resource R.drawable.ic_action_search appears to be unused
Issue: Looks for unused resources
Id: UnusedResources
Unused resources make applications larger and slow down builds.
7.DrawAllocation 避免在draw和layout的时候创建对象,频繁的调用,垃圾回收操作会影响一些UI的体验
Avoid object allocations during draw/layout operations (preallocate and reuse instead)
Issue: Looks for memory allocations within drawing code
Id: DrawAllocation
You should avoid allocating objects during a drawing or layout operation. These are called frequently, so a smooth UI can be interrupted by garbage collection pauses caused by the object allocations.
The way this is generally handled is to allocate the needed objects up front and to reuse them for each drawing operation.
Some methods allocate memory on your behalf (such as Bitmap.create), and these should be handled in the same way.
8.UseCompoundDrawables
This tag and its children can be replaced by one <TextView/> and a compound drawable
Issue: Checks whether the current node can be replaced by a TextView using compound drawables.
Id: UseCompoundDrawables
A LinearLayout which contains an ImageView and a TextView can be more efficiently handled as a compound drawable.
There's a lint quickfix to perform this conversion in the Eclipse plugin.
9.MergeRootFrame
This <FrameLayout> can be replaced with a <merge> tag
Issue: Checks whether a root <FrameLayout> can be replaced with a <merge> tag
Id: MergeRootFrame
If a <FrameLayout> is the root of a layout and does not provide background or padding etc, it can often be replaced with a <merge> tag which is slightly more efficient. Note that this depends on context, so make sure you understand how the <merge> tag works before proceeding.
http://android-developers.blogspot.com/2009/03/android-layout-tricks-3-optimize-by.html
10.UselessParent 有些Layout可以省略
This LinearLayout layout or its FrameLayout parent is useless
Issue: Checks whether a parent layout can be removed.
Id: UselessParent
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.
英文版转自:http://blog.csdn.net/time_hunter/article/details/8664665
Android tips tool 发现的性能问题(转载翻译)的更多相关文章
- Android Tips – 填坑手册
出于: androidChina http://www.androidchina.net/3595.html 学习 Android 至今,大大小小的坑没少踩,庆幸的是,在强大的搜索引擎与无私奉献的 ...
- Android性能測试 一些适用于Android Studio的代码审查和性能測试工具
导言: Android应用在CPU占用,内存消耗方面的性能指标是影响产品质量的重要因素,因为QQ管家,360手机助手等应用都提供直观的内存消耗,流量监控功能,致使用户比以往更加关注软件的性能,并以此进 ...
- Android图片处理(Matrix,ColorMatrix) - 转载
Android图片处理(Matrix,ColorMatrix) 转载自:http://www.cnblogs.com/leon19870907/articles/1978065.html 在编程中有时 ...
- [Android]使用Dagger 2来构建UserScope(翻译)
以下内容为原创,欢迎转载,转载请注明 来自天天博客:http://www.cnblogs.com/tiantianbyconan/p/6237731.html 使用Dagger 2来构建UserSco ...
- [Android]使用Dagger 2依赖注入 - API(翻译)
以下内容为原创,欢迎转载,转载请注明 来自天天博客:http://www.cnblogs.com/tiantianbyconan/p/5092525.html 使用Dagger 2依赖注入 - API ...
- [转载]Android利用convertView优化ListView性能
本的getView写法 Java代码public View getView(int position, View convertView, ViewGroup parent) {View view = ...
- android性能小贴士 翻译
转自http://developer.android.com/training/articles/perf-tips.html 性能小贴士: 这篇文档主要一些微优化可以提升应用程序性能,但是这些改变不 ...
- Android_性能优化转载
胡凯 RSS Blog Archives Android Training in Chinese About Android性能优化典范 JAN 17TH, 2015 | COMMENTS 2015年 ...
- Graphic32中TBitmap32.TextOut性能分析[转载]
转载:http://blog.csdn.net/avan_lau/article/details/6958497 最近在分析软件中画线效率问题,发现在画一些标志性符号的方法,存在瓶颈,占用较大的时间. ...
随机推荐
- php 使用当前时间点进行时间范围查询
/** * 判断是否是吃早饭时间 */ $nowtime = time(); $start = strtotime('8:30:00'); $end = strtotime('9:30:00'); i ...
- 事物总线模式实例——EventBus实例详解
事件总线模式是一种广泛运用于安卓开发之中的一种软件架构模式,而事件总线模式在安卓开发中最广泛的应用莫过于AndroidStudio提供的EventBus,所以我就EventBus来谈谈对事件总线模式的 ...
- 06 python操作MySQL和redis(进阶)
python操作mysql.redis 阶段一.mysql事务 主要用于处理操作量大,复杂度高的数据.比如说,在人员管理系统中,你删除一个人员,你即需要删除人员的基本资料,也要删除和该人员相关的信息, ...
- C语言实例解析精粹学习笔记——32
实例32: 编制一个包含姓名.地址.邮编和电话的通讯录输入和输出函数. 思路解析: 1.用结构体来完成姓名.地址.邮编和电话的组合. 2.结构体指针的使用. 3.malloc的使用 4.scanf函数 ...
- Django学习之天气调查实例(3):部署静态文件CSS、JS、images等(部署环境基于Ubuntu)
在设计登录界面时,采用了网上下载的登录模板,漂亮,简易.但是在测试和部署时,发现原来模板中采用的js文件和css文件,却着实让我折腾了好几天. 在以往的网页设计中,一般只要把测试站点开启后,网页中的静 ...
- HTML布局的元素
header 定义文档或节的页眉 nav 定义导航链接的容器 section 定义文档中的节 article 定义独立的自包含文章 aside 定义内容之外的内容(比如侧栏) footer 定义文档或 ...
- mac 下 安装php扩展 - mcrypt
由于自带的libmcrypt 可能版本低 另外通过brew安装的也不管用得去下载libmcrypt后编译安装 tar zxvf libmcrypt-2.5.8.tar.gz cd libmcrypt- ...
- Delphi实例之绘制正弦函数图像
Delphi实例之绘制正弦函数图像 unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphic ...
- 最小总代价 状压DP
描述 n个人在做传递物品的游戏,编号为1-n. 游戏规则是这样的:开始时物品可以在任意一人手上,他可把物品传递给其他人中的任意一位:下一个人可以传递给未接过物品的任意一人. 即物品只能经过同一个人一次 ...
- VIN码识别:助力汽车后市场转型升级
随着中国汽车市场的成熟,汽车后市场发展迅速,呈“井喷”式增长.据最新数据统计,2015年,中国汽车后市场产值突破8000亿规模,到2018年有望突破万亿. 所谓汽车后市场是指汽车销售以后,围绕汽车使用 ...