DashPathEffect not working

由于公司的文字渲染引擎是自己实现的,在对单词进行标识时用到了虚线下划线的效果,通过 Paint 设置 setPathEffect() 方法,其中 DashPathEffect 类是官方提供的设置虚线的显示效果。在源码注释中明确说明 Paint 的 style 设置成 STROKE or FILL_AND_STROKE 才会生效。最近发现在高版本的 Android 设备(8.0)上,原本应该显示的虚线变成了实线。

官方的 API 在最新的 Android P 中并未对 DashPathEffect 类的说明进行修改

The intervals array must contain an even number of entries (>=2), with the even indices specifying the "on" intervals, and the odd indices specifying the "off" intervals. phase is an offset into the intervals array (mod the sum of all of the intervals). The intervals array controls the length of the dashes. The paint's strokeWidth controls the thickness of the dashes. Note: this patheffect only affects drawing with the paint's style is set to STROKE or FILL_AND_STROKE. It is ignored if the drawing is done with style == FILL.

然而,莫名其妙的在高版本失效,肯定是版本导致的问题。

Paint 中的 setPathEffect() 方法都是调用 Native 方法实现的,未能看到具体的实现逻辑。

所以只能尝试修改 Paint 的一些设置。

最终发现, style 设置成 FILL_AND_STROKE 是无效的, 设置成 STROKE 才能在高版本中完美展示虚线效果。

虽然是一个很小的问题,但是文档没有更新真心很坑。

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • rljs by sennchi Timeline of History Part One The Cognitiv...
    sennchi阅读 7,424评论 0 10
  • 今晚下了手术,于未读消息中得知,家人去给爷爷扫墓了,他老人家就安居于山道旁高处的一小块空地上,那里能隐隐看到进山的...
    狐仙凉凉阅读 198评论 0 1
  • 童年 小时候 爸爸打我的时候 乌云总是布满了头上的天空 我的妈妈被悲伤笼罩 我一次次懊恼 悔恨 挣扎 一片片拾起 ...
    却悔阅读 176评论 0 4
  • 学生时期的年总结都是放在学年结束的时候写的,现在以实习生的身份处于半职场状态,第一次以农历年的节点写年总结,以后也...
    且行且停的lancy阅读 377评论 0 0