What is the substitute for deprecated StaticLayout

别说谁变了你拦得住时间么 提交于 2019-12-07 05:59:35

问题


What should be used instead of:

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

Gives this warning:

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);


回答1:


Use StaticLayout.Builder. Go through here for more details: https://developer.android.com/reference/android/text/StaticLayout.Builder

for your case use:

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


来源:https://stackoverflow.com/questions/53105715/what-is-the-substitute-for-deprecated-staticlayout

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!