How do I setMaskfilter without crash on Android O?

我只是一个虾纸丫 提交于 2019-12-11 02:34:23

问题


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);

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


回答1:


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 );

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



来源:https://stackoverflow.com/questions/49578296/how-do-i-setmaskfilter-without-crash-on-android-o

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!