Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the substitute for deprecated StaticLayout

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

like image 596
MiguelSlv Avatar asked Nov 01 '18 16:11

MiguelSlv


1 Answers

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, 0, text.length(), paint, width)
                          .setAlignment(Layout.Alignment.ALIGN_NORMAL)
                          .setLineSpacing(mSpacingAdd, mSpacingMult)
                          .setIncludePad (false);
StaticLayout layout = sb.build();
like image 135
S.M Avatar answered Oct 23 '22 13:10

S.M