public class

StaticLayoutCompat.Builder

extends java.lang.Object

 java.lang.Object

↳androidx.text.StaticLayoutCompat.Builder

Overview

Builder class for StaticLayout.

Summary

Constructors
publicBuilder(java.lang.CharSequence text, TextPaint paint, int width)

Builder for StaticLayout.

Methods
public StaticLayoutbuild()

Build the StaticLayout after options have been set.

public StaticLayoutCompat.BuildersetAddLastLineLineSpacing(boolean value)

Sets whether the line spacing should be applied for the last line.

public StaticLayoutCompat.BuildersetAlignment(Layout.Alignment alignment)

Set the alignment.

public StaticLayoutCompat.BuildersetBreakStrategy(int breakStrategy)

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

public StaticLayoutCompat.BuildersetEllipsize(TextUtils.TruncateAt ellipsize)

Set ellipsizing on the layout.

public StaticLayoutCompat.BuildersetEllipsizedWidth(int ellipsizedWidth)

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

public StaticLayoutCompat.BuildersetEnd(int end)

Set the end of the text.

public StaticLayoutCompat.BuildersetHyphenationFrequency(int hyphenationFrequency)

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

public StaticLayoutCompat.BuildersetIncludePad(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).

public StaticLayoutCompat.BuildersetIndents(int[] leftIndents[], int[] rightIndents[])

Set indents.

public StaticLayoutCompat.BuildersetJustificationMode(int justificationMode)

Set paragraph justification mode.

public StaticLayoutCompat.BuildersetLineSpacingExtra(float lineSpacingExtra)

Set line spacing extra.

public StaticLayoutCompat.BuildersetLineSpacingMultiplier(float lineSpacingMultiplier)

Set line spacing multiplier.

public StaticLayoutCompat.BuildersetMaxLines(int maxLines)

Set maximum number of lines.

public StaticLayoutCompat.BuildersetPaint(TextPaint paint)

Set the paint.

public StaticLayoutCompat.BuildersetStart(int start)

Set the start of the text.

public StaticLayoutCompat.BuildersetText(java.lang.CharSequence text)

Set the text.

public StaticLayoutCompat.BuildersetText(java.lang.CharSequence text, int start, int end)

Set the text.

public StaticLayoutCompat.BuildersetTextDirection(TextDirectionHeuristic textDir)

Set the text direction heuristic.

public StaticLayoutCompat.BuildersetUseLineSpacingFromFallbacks(boolean useLineSpacingFromFallbacks)

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

public StaticLayoutCompat.BuildersetWidth(int width)

Set the width.

from java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Constructors

public Builder(java.lang.CharSequence text, TextPaint paint, int width)

Builder for StaticLayout.

Parameters:

text: The text to be laid out, optionally with spans
paint: The base paint used for layout
width: The width in pixels

Methods

public StaticLayoutCompat.Builder setText(java.lang.CharSequence text)

Set the text. Only useful when re-using the builder.

Parameters:

text: The text to be laid out, optionally with spans

Returns:

this builder, useful for chaining

public StaticLayoutCompat.Builder setText(java.lang.CharSequence text, int start, int end)

Set the text. Only useful when re-using the builder.

Parameters:

text: The text to be laid out, optionally with spans
start: The index of the start of the text
end: The index + 1 of the end of the text

Returns:

this builder, useful for chaining

public StaticLayoutCompat.Builder setStart(int start)

Set the start of the text. Should be in range of [0, end], which is checked in StaticLayoutCompat.Builder.build()

Parameters:

start: The index of the start of the text

Returns:

this builder, useful for chaining

public StaticLayoutCompat.Builder setEnd(int end)

Set the end of the text. Should be in range of [start, text.length], which is checked in StaticLayoutCompat.Builder.build().

Parameters:

end: The index + 1 of the end of the text.

Returns:

this builder, useful for chaining

public StaticLayoutCompat.Builder setPaint(TextPaint paint)

Set the paint. Internal for reuse cases only.

Parameters:

paint: The base paint used for layout

Returns:

this builder, useful for chaining

public StaticLayoutCompat.Builder setWidth(int width)

Set the width. Internal for reuse cases only.

Parameters:

width: The width in pixels

Returns:

this builder, useful for chaining

public StaticLayoutCompat.Builder setAlignment(Layout.Alignment alignment)

Set the alignment. The default is .

Parameters:

alignment: Alignment for the resulting StaticLayout

Returns:

this builder, useful for chaining

public StaticLayoutCompat.Builder setTextDirection(TextDirectionHeuristic textDir)

Set the text direction heuristic. The text direction heuristic is used to resolve text direction per-paragraph based on the input text. The default is .

Parameters:

textDir: text direction heuristic for resolving bidi behavior.

Returns:

this builder, useful for chaining

public StaticLayoutCompat.Builder setLineSpacingExtra(float lineSpacingExtra)

Set line spacing extra. Each line will have its line spacing increased by lineSpacingExtra. The default value is 0.0f.

Parameters:

lineSpacingExtra: the amount of line spacing addition

Returns:

this builder, useful for chaining

See also: android.widget.TextView

public StaticLayoutCompat.Builder setLineSpacingMultiplier(float lineSpacingMultiplier)

Set line spacing multiplier. Each line will have its line spacing multiplied by lineSpacingMultiplier. The default value is 1.0f, and lineSpacingMultiplier should be non-negative.

Parameters:

lineSpacingMultiplier: the line spacing multiplier

Returns:

this builder, useful for chaining

See also: android.widget.TextView

public StaticLayoutCompat.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). The default is true.

Parameters:

includePad: whether to include padding

Returns:

this builder, useful for chaining

See also: android.widget.TextView

public StaticLayoutCompat.Builder setUseLineSpacingFromFallbacks(boolean useLineSpacingFromFallbacks)

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.

For backward compatibility reasons, the default is false, but setting this to true is strongly recommended. 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:

useLineSpacingFromFallbacks: whether to expand linespacing based on fallback fonts

Returns:

this builder, useful for chaining

public StaticLayoutCompat.Builder setEllipsize(TextUtils.TruncateAt ellipsize)

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 of or , to be ellipsized instead of broken. The default is null, indicating no ellipsis is to be applied.

Parameters:

ellipsize: type of ellipsis behavior

Returns:

this builder, useful for chaining

See also: android.widget.TextView

public StaticLayoutCompat.Builder setEllipsizedWidth(int ellipsizedWidth)

Set the width as used for ellipsizing purposes, if it differs from the normal layout width. The default is the width passed to StaticLayoutCompat.Builder.Builder(CharSequence, TextPaint, int).

Parameters:

ellipsizedWidth: width used for ellipsizing, in pixels

Returns:

this builder, useful for chaining

See also: android.widget.TextView

public StaticLayoutCompat.Builder setMaxLines(int maxLines)

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

See also: android.widget.TextView

public StaticLayoutCompat.Builder setBreakStrategy(int breakStrategy)

Set break strategy, useful for selecting high quality or balanced paragraph layout options. The default is Layout.

Enabling hyphenation with either using Layout or Layout while line breaking is set to one of Layout, Layout improves the structure of text layout however has performance impact and requires more time to do the text layout.

Parameters:

breakStrategy: break strategy for paragraph layout

Returns:

this builder, useful for chaining

See also: android.widget.TextView, StaticLayoutCompat.Builder.setHyphenationFrequency(int)

public StaticLayoutCompat.Builder setHyphenationFrequency(int hyphenationFrequency)

Set hyphenation frequency, to control the amount of automatic hyphenation used. The possible values are defined in Layout, by constants named with the pattern HYPHENATION_FREQUENCY_*. The default is Layout.

Enabling hyphenation with either using Layout or Layout while line breaking is set to one of Layout, Layout improves the structure of text layout however has performance impact and requires more time to do the text layout.

Parameters:

hyphenationFrequency: hyphenation frequency for the paragraph

Returns:

this builder, useful for chaining

See also: android.widget.TextView, StaticLayoutCompat.Builder.setBreakStrategy(int)

public StaticLayoutCompat.Builder setIndents(int[] leftIndents[], 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 pixels
rightIndents: array of indent values for right margin, in pixels

Returns:

this builder, useful for chaining

public StaticLayoutCompat.Builder setJustificationMode(int justificationMode)

Set paragraph justification mode. The default value is Layout. If the last line is too short for justification, the last line will be displayed with the alignment set by StaticLayoutCompat.Builder.setAlignment(Layout.Alignment).

Parameters:

justificationMode: justification mode for the paragraph.

Returns:

this builder, useful for chaining.

public StaticLayoutCompat.Builder setAddLastLineLineSpacing(boolean value)

Sets whether the line spacing should be applied for the last line. Default value is false.

public StaticLayout build()

Build the StaticLayout after options have been set.

Returns:

the newly constructed StaticLayout object