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.

Andorid Nougat, unexpected result.

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.