Android tips tool 发现的性能问题

转载 2013年05月12日 18:41:01

1.ObsoleteLayoutParam不起作用的标签

Invalid layout param in a LinearLayout: layout_centerVertical


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 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.



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.

Android tips tool 发现的性能问题

1.ObsoleteLayoutParam不起作用的标签 Invalid layout param in a LinearLayout: layout_centerVertical Iss...

Android性能优化系列——Performance Tips

本文列出的优化技巧主要是一些微小的性能提升,可能不会给你的程序性能改善产生显著的效果。因为程序的整体性能仍然主要取决于程序的业务逻辑设计、代码的...
  • xhmj12
  • xhmj12
  • 2016年02月21日 10:16
  • 371

Android性能优化之Performance Tips

这篇文章主要是对官方文档中PerformanceTips(性能优化关键点)的翻译,欢迎拍砖。...

Android性能优化建议 Performance Tips

Avoid Creating Unnecessary Objects Prefer Static Over Virtual Use Static Final For Constants Avoid I...

Android性能优化Tips

一、Google官方tips 以下是一些关键点记录,详细看http://developer.android.com/training/articles/perf-tips.html ...
  • zmissm
  • zmissm
  • 2013年10月23日 09:42
  • 474

[Android--Tool]使用activity-lifecycle源码建立工程无R.java的问题

问题描述:Andriod工程的R.java是自动生成的,当改变程序代码,XML文档内容时,都会自动添加上内容的。之前对R.java做过了解和修改,并整理了网络一些关于R.java的资料。     先新...

如何解决Android sdk tool的下载不成功的问题

相信很多人在开发安卓的时候都会出现安卓插件下载不成功的问题,基本上都是访问被墙了问题,所以以下告诉大家怎么解决方便快捷地解决这个问题: 1.注册个ssh账号,然后里面有试用的VPN账号,貌似近端时间...

[Android Tool]SDK Manager无法下载的问题解决

问题描述:使用ADT工具的SDK Manager下载和更新Android SDK非常方便,一切自动完成,但是有两次SDK Manager出问题了,许多内容无法完成更新。于是进行了了解。以下内容参考...

Android tips(十四)-->解决AppBarLayout滑动不畅的问题

最近在开发的App中需要实现Toolbar与顶部内容区域级联滚动的效果,一开始就想到了Android 5.0 中新添加的AppBarLayout控件,其正好是实现这个效果的,所以马上就使用这个组件实现...

Android Studio Tips(部分问题可能集成ionic才会出现)

导入项目时进度条卡住不动查看gradle版本:C:\Users\用户名\.gradle\wrapper\dists\gradle-1.XX-all 存放位置:C:\Users\用户名\.gradle\...
  • xundh
  • xundh
  • 2016年08月11日 07:53
  • 1487
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:Android tips tool 发现的性能问题
举报原因:
原因补充:

(最多只允许输入30个字)