Android PathMeasure.getSegment方法注意项

boolean getSegment (float startD, 
                float stopD, 
                Path dst, 
                boolean startWithMoveTo)

Given a start and stop distance, return in dst the intervening segment(s). If the segment is zero-length, return false, else return true. startD and stopD are pinned to legal values (0..getLength()). If startD >= stopD then return false (and leave dst untouched). Begin the segment with a moveTo if startWithMoveTo is true.

On KITKAT and earlier releases, the resulting path may not display on a hardware-accelerated Canvas. A simple workaround is to add a single operation to this path, such asdst.rLineTo(0, 0).

以上是官方文档的解释。

在使用该方法时要注意On KITKAT and earlier releases, the resulting path may not display on a hardware-accelerated Canvas. A simple workaround is to add a single operation to this path, such asdst.rLineTo(0, 0).这句话的解释。

这句话的意思是:在android KITKAT版本及之前的版本,该方法所获取到的path是无法被绘制显示出来的。要解决该问题的简单方法就是在所要获取的path上执行lineTo(0, 0) 或执行rLineTo(0, 0);

例子:

public void setDistance(float distance) {
        this.distance = distance;
        
        mDstPath.reset();
        mDstPath.lineTo(0, 0);
        mPathMeasure.getSegment(0, distance, mDstPath, true);
        invalidate();
    }

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值