前言
使用BiuTextView替代TextView来实现跑马灯。
注意,下面测试还要其他应用使用surfaceflinger,所以很高,我们只是对比同一环境下,BiuTextView和TextView跑马灯的情况。
正文
说明:Demo中只放了1个TextView或BiuTextView进行跑马灯
TextView跑马灯
只要当前界面有TextView的走马灯,CPU占用就高起来。
可以通过
//比如过滤:com.biumall.demo adb shell top | grep demo
grep跟当前电脑环境有关
这里只看surfaceflinger和走马灯CPU占用情况
命令查看某个进程的CPU占用
103 surfaceflinger 37.5 com.biumall.demo+ 104 surfaceflinger 36.0 com.biumall.demo+ 103 surfaceflinger 36.6 com.biumall.demo+ 108 surfaceflinger 33.6 com.biumall.demo+ 90.0 surfaceflinger 38.0 com.biumall.demo+ 108 surfaceflinger 37.6 com.biumall.demo+ 107 surfaceflinger 37.3 com.biumall.demo+ 105 surfaceflinger 36.6 com.biumall.demo+ 103 surfaceflinger 38.0 com.biumall.demo+ 73.3 surfaceflinger 40.3 com.biumall.demo+ 53.0 surfaceflinger 26.6 com.biumall.demo+ 65.0 surfaceflinger 39.6 com.biumall.demo+ 72.6 surfaceflinger 44.6 com.biumall.demo+ 73.0 surfaceflinger 42.3 com.biumall.demo+ 72.6 surfaceflinger 42.6 com.biumall.demo+ 80.6 surfaceflinger 39.6 com.biumall.demo+ 73.3 surfaceflinger 48.0 com.biumall.demo+ 73.0 surfaceflinger 44.6 com.biumall.demo+ 78.3 surfaceflinger 45.6 com.biumall.demo+ 75.0 surfaceflinger 42.6 com.biumall.demo+ 103 surfaceflinger 31.6 com.biumall.demo+ 66.0 surfaceflinger 19.0 com.biumall.demo+ 86.0 surfaceflinger 39.0 com.biumall.demo+ 101 surfaceflinger 37.3 com.biumall.demo+ 106 surfaceflinger 35.0 com.biumall.demo+ 106 surfaceflinger 33.6 com.biumall.demo+ 106 surfaceflinger 36.0 com.biumall.demo+ 109 surfaceflinger 38.0 com.biumall.demo+ 107 surfaceflinger 39.0 com.biumall.demo+ 106 surfaceflinger 38.6 com.biumall.demo+ 108 surfaceflinger 32.0 com.biumall.demo+ 107 surfaceflinger 28.6 com.biumall.demo+ 66.6 surfaceflinger 20.6 com.biumall.demo+ 108 surfaceflinger 34.0 com.biumall.demo+ 107 surfaceflinger 33.6 com.biumall.demo+ 106 surfaceflinger 33.3 com.biumall.demo+ 107 surfaceflinger 33.6 com.biumall.demo+
开启走马灯后,当前com.biumall.demo占用持续在40%左右,而且surfaceflinger也很高。
BiuTextView跑马灯
使用《》中自定义的BiuTextView
43.3 surfaceflinger 3.3 com.biumall.demo+ 20.6 surfaceflinger 3.6 com.biumall.demo+ 37.6 surfaceflinger 6.3 com.biumall.demo+ 37.0 surfaceflinger 5.6 com.biumall.demo+ 38.0 surfaceflinger 6.0 com.biumall.demo+ 38.3 surfaceflinger 6.3 com.biumall.demo+ 39.3 surfaceflinger 6.3 com.biumall.demo+ 61.3 surfaceflinger 6.6 com.biumall.demo+ 61.6 surfaceflinger 6.6 com.biumall.demo+ 61.6 surfaceflinger 6.3 com.biumall.demo+ 33.3 surfaceflinger 3.3 com.biumall.demo+ 62.3 surfaceflinger 5.6 com.biumall.demo+ 61.3 surfaceflinger 6.0 com.biumall.demo+ 59.3 surfaceflinger 5.6 com.biumall.demo+ 58.0 surfaceflinger 5.6 com.biumall.demo+ 61.3 surfaceflinger 6.0 com.biumall.demo+ 61.3 surfaceflinger 6.3 com.biumall.demo+ 61.6 surfaceflinger 6.0 com.biumall.demo+ 63.6 surfaceflinger 6.0 com.biumall.demo+ 61.0 surfaceflinger 6.0 com.biumall.demo+ 33.6 surfaceflinger 3.6 com.biumall.demo+ 60.6 surfaceflinger 6.3 com.biumall.demo+ 61.6 surfaceflinger 6.0 com.biumall.demo+ 61.0 surfaceflinger 6.0 com.biumall.demo+ 60.3 surfaceflinger 5.6 com.biumall.demo+ 61.3 surfaceflinger 6.3 com.biumall.demo+ 62.3 surfaceflinger 6.6 com.biumall.demo+ 38.6 surfaceflinger 6.3 com.biumall.demo+ 38.0 surfaceflinger 6.6 com.biumall.demo+ 25.0 surfaceflinger 3.3 com.biumall.demo+ 62.0 surfaceflinger 6.0 com.biumall.demo+ 61.6 surfaceflinger 7.6 com.biumall.demo+ 62.0 surfaceflinger 5.6 com.biumall.demo+ 64.6 surfaceflinger 5.6 com.biumall.demo+
测试中发现,使用SurfaceView自定义走马灯,com.biumall.demo和surfaceflinger占用较低些。
小结
虽然只是单一的一次数据,但从上面大致可以了解到。
TextView跑马灯时com.biumall.demo占CPU比较高
在CPU为稀缺情况下,能少占一点就尽可能少占一点。空闲CPU过少,容易导致系统卡顿。因此,如果需要跑马灯,个人推荐还是使用BiuTextView替换TextView。
复杂情况下没怎么测试,比如ListView中等列表中可能有问题。
参考文章
《
© 版权声明