3

I render text via StaticLayout and draw it in onDraw() in my custom view, not TextView. Everything works fine until I test my application with Android Nougat. In some cases, StaticLayout is created wrongly with lineWidth bigger than the outerWidth that I passed in constructor(). So It causes my custom view renders wrongly. (outside the limited area)
Android Marshmallow, expected result.
enter image description here

Andorid Nougat, unexpected result.
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
    ....
}

I don't know what the rule is to cause that error. (If I change the outerWidth or the text, the error doesn't happen.)
Could anyone help em? Thanks in advance.

Huy Duong Tu
  • 7,238
  • 5
  • 22
  • 45

0 Answers0