LineBreaker.Builder


public static final class LineBreaker.Builder
extends Object

java.lang.Object
   ↳ android.graphics.text.LineBreaker.Builder


Helper class for creating a LineBreaker.

Summary

Public constructors

Builder()

Public methods

LineBreaker build()

Build a new LineBreaker with given parameters.

LineBreaker.Builder setBreakStrategy(int breakStrategy)

Set break strategy.

LineBreaker.Builder setHyphenationFrequency(int hyphenationFrequency)

Set hyphenation frequency.

LineBreaker.Builder setIndents(int[] indents)

Set indents.

LineBreaker.Builder setJustificationMode(int justificationMode)

Set whether the text is justified.

LineBreaker.Builder setUseBoundsForWidth(boolean useBoundsForWidth)

Set true for using width of bounding box as a source of automatic line breaking.

Inherited methods

Public constructors

Builder

public Builder ()

Public methods

build

Added in API level 29
public LineBreaker build ()

Build a new LineBreaker with given parameters. You can reuse the Builder instance even after calling this method.

Returns
LineBreaker This value cannot be null.

setBreakStrategy

Added in API level 29
public LineBreaker.Builder setBreakStrategy (int breakStrategy)

Set break strategy. You can change the line breaking behavior by setting break strategy. The default value is LineBreaker.BREAK_STRATEGY_SIMPLE.

Parameters
breakStrategy int: Value is LineBreaker.BREAK_STRATEGY_SIMPLE, LineBreaker.BREAK_STRATEGY_HIGH_QUALITY, or LineBreaker.BREAK_STRATEGY_BALANCED

Returns
LineBreaker.Builder This value cannot be null.

setHyphenationFrequency

Added in API level 29
public LineBreaker.Builder setHyphenationFrequency (int hyphenationFrequency)

Set hyphenation frequency. You can change the amount of automatic hyphenation used. The default value is LineBreaker.HYPHENATION_FREQUENCY_NONE.

Parameters
hyphenationFrequency int: Value is LineBreaker.HYPHENATION_FREQUENCY_NORMAL, LineBreaker.HYPHENATION_FREQUENCY_FULL, or LineBreaker.HYPHENATION_FREQUENCY_NONE

Returns
LineBreaker.Builder This value cannot be null.

setIndents

Added in API level 29
public LineBreaker.Builder setIndents (int[] indents)

Set indents. The supplied array provides the total amount of indentation per line, in pixel. This amount is the sum of both left and right indentations. For lines past the last element in the array, the indentation amount of the last element is used.

Parameters
indents int: This value may be null.

Returns
LineBreaker.Builder This value cannot be null.

setJustificationMode

Added in API level 29
public LineBreaker.Builder setJustificationMode (int justificationMode)

Set whether the text is justified. By setting LineBreaker.JUSTIFICATION_MODE_INTER_WORD, the line breaker will change the internal parameters for justification. The default value is LineBreaker.JUSTIFICATION_MODE_NONE

Parameters
justificationMode int: Value is LineBreaker.JUSTIFICATION_MODE_NONE, LineBreaker.JUSTIFICATION_MODE_INTER_WORD, or LineBreaker.JUSTIFICATION_MODE_INTER_CHARACTER

Returns
LineBreaker.Builder This value cannot be null.

setUseBoundsForWidth

Added in API level 35
public LineBreaker.Builder setUseBoundsForWidth (boolean useBoundsForWidth)

Set true for using width of bounding box as a source of automatic line breaking. If this value is false, the automatic line breaking uses total amount of advances as text widths. By setting true, it uses joined all glyph bound's width as a width of the text. If the font has glyphs that have negative bearing X or its xMax is greater than advance, the glyph clipping can happen because the drawing area may be bigger. By setting this to true, the line breaker will break line based on bounding box, so clipping can be prevented.

Parameters
useBoundsForWidth boolean: True for using bounding box, false for advances.

Returns
LineBreaker.Builder this builder instance This value cannot be null.