什么是已弃用的 StaticLayout 的替代品

What is the substitute for deprecated StaticLayout

应该用什么代替:

StaticLayout layout = new StaticLayout(text, paint, width, Alignment.ALIGN_NORMAL, mSpacingMult, mSpacingAdd, false);

发出此警告:

warning: [deprecation] StaticLayout(CharSequence,TextPaint,int,Alignment,float,float,boolean) in StaticLayout has been deprecated StaticLayout layout = new StaticLayout(text, paint, width, Alignment.ALIGN_NORMAL, mSpacingMult, mSpacingAdd, false);

使用StaticLayout.Builder。 通过此处了解更多详细信息:https://developer.android.com/reference/android/text/StaticLayout.Builder

您的案例使用:

StaticLayout.Builder sb = StaticLayout.Builder.obtain(text, 0, text.length(), paint, width)
                          .setAlignment(Layout.Alignment.ALIGN_NORMAL)
                          .setLineSpacing(mSpacingAdd, mSpacingMult)
                          .setIncludePad (false);
StaticLayout layout = sb.build();