path 动画与canvas 动画在部分机型不显示的问题

最近在用path写一个心电图动画,发现动画完成以后在5.0以上正常显示,5.0以下的机型不显示,反复看了代码发现PathMeasure的getSegment(float startD, float stopD, Path dst, boolean startWithMoveTo)在API<=19的时候开启硬件加速会引起这个path 动画不可见。

先说官方提供的解决方案:在调用getSegment(float startD, float stopD, Path dst, boolean startWithMoveTo)之后再加一行代码:dst.rLineTo(0, 0)即可解决硬件加速的bug。

看了官方文档点击打开链接第二段中有说

However, because hardware acceleration is not supported for all of the 2D drawing operations, turning it on might affect some of your custom views or drawing calls. Problems usually manifest themselves as invisible elements, exceptions, or wrongly rendered pixels. To remedy this, Android gives you the option to enable or disable hardware acceleration at multiple levels. See Controlling Hardware Acceleration.

但是,由于所有2D绘图操作都不支持硬件加速,因此将其打开可能会影响某些自定义视图或绘图调用。问题通常表现为不可见的元素,例外或错误渲染的像素。为了解决这个问题,Android允许您在多个级别启用或禁用硬件加速。请参阅控制硬件加速。

硬件加速的原理请参考点击打开链接



你可能感兴趣的:(解决bug)