六狼论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博账号登陆

只需一步,快速开始

搜索
查看: 109|回复: 0

Android View 性能优化

[复制链接]

升级  50.67%

112

主题

112

主题

112

主题

举人

Rank: 3Rank: 3

积分
352
 楼主| 发表于 2012-12-19 23:08:40 | 显示全部楼层 |阅读模式
Android View 性能优化

<div class="postText"><div id="cnblogs_post_body">Tips and Tricks

Switching to hardware accelerated 2D graphics can instantly increase performance, but you should still design your application to use the GPU effectively by following these recommendations:
Reduce the number of views in your applicationThe more views the system has to draw, the slower it will be. This applies to the software rendering pipeline as well. Reducing views is one of the easiest ways to optimize your UI.Avoid overdrawDo not draw too many layers on top of each other. Remove any views that are completely obscured by other opaque views on top of it. If you need to draw several layers blended on top of each other, consider merging them into a single layer. A good rule of thumb with current hardware is to not draw more than 2.5 times the number of pixels on screen per frame (transparent pixels in a bitmap count!).Don't create render objects in draw methodsA common mistake is to create a new Paint or a new Path every time a rendering method is invoked. This forces the garbage collector to run more often and also bypasses caches and optimizations in the hardware pipeline.Don't modify shapes too oftenComplex shapes, paths, and circles for instance, are rendered using texture masks. Every time you create or modify a path, the hardware pipeline creates a new mask, which can be expensive.Don't modify bitmaps too oftenEvery time you change the content of a bitmap, it is uploaded again as a GPU texture the next time you draw it.Use alpha with careWhen you make a view translucent using setAlpha(), AlphaAnimation, or ObjectAnimator, it is rendered in an off-screen buffer which doubles the required fill-rate. When applying alpha on very large views, consider setting the view's layer type to LAYER_TYPE_HARDWARE.
您需要登录后才可以回帖 登录 | 立即注册 新浪微博账号登陆

本版积分规则

快速回复 返回顶部 返回列表