StaticLayout使用Android Nougat错误地渲染

时间:2016-09-09 07:09:13

标签: android android-7.0-nougat staticlayout

我通过StaticLayout呈现文字,并在我的自定义视图中的onDraw()中绘制文字,而不是TextView。一切正常,直到我用Android Nougat测试我的应用程序。在某些情况下,StaticLayout错误地创建lineWidth大于outerWidth传递的constructor()。所以它导致我的自定义视图呈现错误。 (限制区域外)
Android Marshmallow,预期结果。
enter image description here

Andorid Nougat,出乎意料的结果。
enter image description here

StaticLayout textLayout = new StaticLayout(text, paint, outerwidth, Layout.Alignment.ALIGN_NORMAL, 1.0f, 0.0f, false);
for (int i = 0; i < textLayout.getLineCount(); i++) {
    lineWidth = textLayout.getLineWidth(i); // lineWidth sometimes is bigger than outerWidth
    ....
}

我不知道导致该错误的规则是什么。 (如果我更改外部宽度或文本,则不会发生错误。)
谁能帮助他们?提前谢谢。

0 个答案:

没有答案