我通过StaticLayout
呈现文字,并在我的自定义视图中的onDraw()
中绘制文字,而不是TextView
。一切正常,直到我用Android Nougat
测试我的应用程序。在某些情况下,StaticLayout
错误地创建lineWidth
大于outerWidth
传递的constructor()
。所以它导致我的自定义视图呈现错误。 (限制区域外)
Android Marshmallow
,预期结果。
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
....
}
我不知道导致该错误的规则是什么。 (如果我更改外部宽度或文本,则不会发生错误。)
谁能帮助他们?提前谢谢。