如何在Android O上无崩溃的情况下设置Maskfilter? [英] How do I setMaskfilter without crash on Android O?

查看:264
本文介绍了如何在Android O上无崩溃的情况下设置Maskfilter?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在网格中使用了RecyclerView.每个项目都有textview和Imageview. 我在适配器中为textview设置了掩码过滤器,如下所示:

I use a RecyclerView in my grid. Each item has textview and Imageview. I set mask filter for textview in my Adapter as below:

float[] direction = new float[]{0.0f, -1.0f, 0.5f};
MaskFilter maskFilter = new EmbossMaskFilter(direction, 0.8f, 15f, 1f);
holder.textview.getPaint().setMaskFilter(maskFilter);

这是第一次运行时崩溃(Fatal signal 11 (SIGSEGV), code 1, fault addr 0xfff8022c in tid 32638 (ReferenceQueueD))的原因.

It is the reason of crash (Fatal signal 11 (SIGSEGV), code 1, fault addr 0xfff8022c in tid 32638 (ReferenceQueueD)) for the firs time run.

推荐答案

bug . 方法canvas.drawText();中的问题 但是我找到了一种避免崩溃的方法,而是使用canvas.drawPath();.

This is known bug. Problem in method canvas.drawText(); But I found a way to avoid crash, by using canvas.drawPath(); instead.

Path path = new Path();
paint.getTextPath( text, 0, text.length(), x, y, path );
canvas.drawPath( path, paint );

如果要在TextView中使用它,则必须扩展此类并创建新的onDraw方法. 享受吧!

If you want to use it in TextView you have to extend this class and create new onDraw method. Enjoy!

这篇关于如何在Android O上无崩溃的情况下设置Maskfilter?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆