Package icyllis.modernui.text
Class StaticLayout.Builder
java.lang.Object
icyllis.modernui.text.StaticLayout.Builder
- Enclosing class:
StaticLayout
Builder for static layouts. The builder is the preferred pattern for constructing
StaticLayout objects and should be preferred over the constructors, particularly to access
newer features. To build a static layout, first call
StaticLayout.builder(CharSequence, int, int, TextPaint, int)
with the required arguments (text, paint, and width), then call setters for optional parameters, and finally
build()
to build the StaticLayout object. Parameters not explicitly set will get
default values.-
Method Summary
Modifier and TypeMethodDescriptionbuild()
Build theStaticLayout
after options have been set.setAlignment
(Layout.Alignment alignment) Set the alignment.setEllipsize
(TextUtils.TruncateAt ellipsize) Set ellipsizing on the layout.setEllipsizedWidth
(int ellipsizedWidth) Set the width as used for ellipsizing purposes, if it differs from the normal layout width.setFallbackLineSpacing
(boolean fallbackLineSpacing) Set whether to respect the ascent and descent of the fallback fonts that are used in displaying the text (which is needed to avoid text from consecutive lines running into each other).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).setIndents
(int[] leftIndents, int[] rightIndents) Set indents.setLineBreakConfig
(LineBreakConfig lineBreakConfig) Set the line break configuration.setMaxLines
(int maxLines) Set maximum number of lines.setTextDirection
(TextDirectionHeuristic textDir) Set the text direction heuristic.
-
Method Details
-
setAlignment
Set the alignment. The default isLayout.Alignment.ALIGN_NORMAL
.- Parameters:
alignment
- Alignment for the resultingStaticLayout
- Returns:
- this builder, useful for chaining
-
setTextDirection
Set the text direction heuristic. The text direction heuristic is used to resolve text direction per-paragraph based on the input text. The default isTextDirectionHeuristics.FIRSTSTRONG_LTR
.- Parameters:
textDir
- text direction heuristic for resolving bidi behavior.- Returns:
- this builder, useful for chaining
-
setIncludePad
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). The default istrue
.- Parameters:
includePad
- whether to include padding- Returns:
- this builder, useful for chaining
-
setFallbackLineSpacing
Set whether to respect the ascent and descent of the fallback fonts that are used in displaying the text (which is needed to avoid text from consecutive lines running into each other). If set, fallback fonts that end up getting used can increase the ascent and descent of the lines that they are used on.The default is
true
. It is required to be true if text could be in languages like Burmese or Tibetan where text is typically much taller or deeper than Latin text.- Parameters:
fallbackLineSpacing
- whether to expand line spacing based on fallback fonts- Returns:
- this builder, useful for chaining
-
setEllipsizedWidth
Set the width as used for ellipsizing purposes, if it differs from the normal layout width. The default is thewidth
passed tobuild()
.- Parameters:
ellipsizedWidth
- width used for ellipsizing, in pixels- Returns:
- this builder, useful for chaining
-
setEllipsize
Set ellipsizing on the layout. Causes words that are longer than the view is wide, or exceeding the number of lines (see #setMaxLines) in the case ofTextUtils.TruncateAt.END
orTextUtils.TruncateAt.MARQUEE
, to be ellipsized instead of broken. The default isnull
, indicating no ellipsis is to be applied.- Parameters:
ellipsize
- type of ellipsis behavior- Returns:
- this builder, useful for chaining
-
setMaxLines
Set maximum number of lines. This is particularly useful in the case of ellipsizing, where it changes the layout of the last line. The default is unlimited.- Parameters:
maxLines
- maximum number of lines in the layout- Returns:
- this builder, useful for chaining
-
setIndents
@NonNull public StaticLayout.Builder setIndents(@Nullable int[] leftIndents, @Nullable int[] rightIndents) Set indents. Arguments are arrays holding an indent amount, one per line, measured in pixels. For lines past the last element in the array, the last element repeats.- Parameters:
leftIndents
- array of indent values for left margin, in pixelsrightIndents
- array of indent values for right margin, in pixels- Returns:
- this builder, useful for chaining
-
setLineBreakConfig
Set the line break configuration. The line break will be passed to native used for calculating the text wrapping. The default value of the line break style isLineBreakConfig.LINE_BREAK_STYLE_NONE
- Parameters:
lineBreakConfig
- the line break configuration for text wrapping.- Returns:
- this builder, useful for chaining.
- See Also:
-
build
Build theStaticLayout
after options have been set.Note: the builder object must not be reused in any way after calling this method. Setting parameters after calling this method, or calling it a second time on the same builder object, will likely lead to unexpected results.
- Returns:
- the newly constructed
StaticLayout
object
-