优化布局在Android–减少过度渲染

通过查看GPU透支来改善应用程序的渲染时间。

What is Overdraw?

Overdraw happens every time the application asks the system to draw something on top of something else. The “Debug GPU Overdraw” tool overlays colours on top of your screen to indicate how many times a pixel has been redrawn.

译文:过度绘制发生的每一次应用要求系统上别的画的东西。“调试GPU透支”工具覆盖上你的屏幕的色彩显示多少次像素被重绘。

How do I enable the tool Debug GPU Overdraw?


  1. Go to Settings on your device.
  2. Go to Developer Options
  3. Select “Debug GPU Overdraw”.
  4. Select “Show overdraw areas”

你打开你的手机到开发人员工具选项—>调试GPU过度绘制—>显示GPU视图更新,当你运行你的程序时,你看着你的手机的颜色变化,来提高你的布局优化。

What do the different colours mean?

我们可以根据颜色来判断布局是否过度绘制以及根据颜色来判断绘制的程度。

Original colour – 没有过度绘制,只在屏幕上绘制过一次

Blue – 1x – 过度绘制,在屏幕上绘制过2次

Green – 2x – 过度绘制,在屏幕上绘制过3次

Pink – 3x –过度绘制,在屏幕上绘制过4次

Red – 4x – 过度绘制,在屏幕上绘制过5次

重绘情况

屏幕绘制图像

How do you fix overdraw?

在上面的例子中,我把背景颜色,设置在相对布局,让主题画的背景。

So going from this:

<RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="#FFFFFF">

to this:

<RelativeLayout
     android:layout_width="match_parent"
     android:layout_height="match_parent">

这里写图片描述
就像你可以看到,透支已经最小化。红色的透支了。你可以进一步改进的布局表现真实的色彩和一点蓝色的透支。有些透支是不可避免的。不是所有情况下的透支是背景颜色相关。其他问题也可能存在,如非常复杂的布局层次结构或太多的视图。你的目标应该是一个最大的透支2X(绿色)。

你也可以使用其他工具来看看为什么透支发生的工具如Hierarchy Viewer和GL示踪。

How do you debug overdraw issues? Do you have any other tips to share?
Also, you should totally Download the Book Dash App or contribute on Github!

Links:

http://developer.android.com/tools/performance/debug-gpu-overdraw/index.html

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值