Added in API level 28

DynamicLayout.Builder


public static final class DynamicLayout.Builder
extends Object

java.lang.Object
   ↳ android.text.DynamicLayout.Builder


Builder for dynamic layouts. The builder is the preferred pattern for constructing DynamicLayout objects and should be preferred over the constructors, particularly to access newer features. To build a dynamic layout, first call obtain(CharSequence, TextPaint, int) with the required arguments (base, paint, and width), then call setters for optional parameters, and finally build() to build the DynamicLayout object. Parameters not explicitly set will get default values.

Summary

Public methods

DynamicLayout build()

Build the DynamicLayout after options have been set.

static DynamicLayout.Builder obtain(CharSequence base, TextPaint paint, int width)

Obtain a builder for constructing DynamicLayout objects.

DynamicLayout.Builder setAlignment(Layout.Alignment alignment)

Set the alignment.

DynamicLayout.Builder setBreakStrategy(int breakStrategy)

Set break strategy, useful for selecting high quality or balanced paragraph layout options.

DynamicLayout.Builder setDisplayText(CharSequence display)

Set the transformed text (password transformation being the primary example of a transformation) that will be updated as the base text is changed.

DynamicLayout.Builder setEllipsize(TextUtils.TruncateAt ellipsize)

Set ellipsizing on the layout.

DynamicLayout.Builder setEllipsizedWidth(int ellipsizedWidth)

Set the width as used for ellipsizing purposes, if it differs from the normal layout width.

DynamicLayout.Builder setHyphenationFrequency(int hyphenationFrequency)

Set hyphenation frequency, to control the amount of automatic hyphenation used.

DynamicLayout.Builder setIncludePad(boolean includePad)

Set whether to include extra space beyond font ascent and descent (which is needed to avoid clipping in some languages, such as Arabic and Kannada).