# DynamicLayout.Builder

Added in[API level 28](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  
Summary:[Methods](https://developer.android.com/reference/android/text/DynamicLayout.Builder#pubmethods)\|[Inherited Methods](https://developer.android.com/reference/android/text/DynamicLayout.Builder#inhmethods)  

# DynamicLayout.Builder

*** ** * ** ***

[Kotlin](https://developer.android.com/reference/kotlin/android/text/DynamicLayout.Builder "View this page in Kotlin")\|Java

`
public
static
final

class
DynamicLayout.Builder
`  
`

extends `[Object](https://developer.android.com/reference/java/lang/Object)`


``


`

|---|------------------------------------|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object) ||
| ↳ | android.text.DynamicLayout.Builder |

<br />

*** ** * ** ***

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)](https://developer.android.com/reference/android/text/DynamicLayout.Builder#obtain(java.lang.CharSequence,%20android.text.TextPaint,%20int))with the required arguments (base, paint, and width), then call setters for optional parameters, and finally[build()](https://developer.android.com/reference/android/text/DynamicLayout.Builder#build())to build the DynamicLayout object. Parameters not explicitly set will get default values.

## Summary

|                                                                                                                                                                                                                                                    ### Public methods                                                                                                                                                                                                                                                     ||
|---------------------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| ` `[DynamicLayout](https://developer.android.com/reference/android/text/DynamicLayout)                        | ` `[build](https://developer.android.com/reference/android/text/DynamicLayout.Builder#build())`() ` Build the[DynamicLayout](https://developer.android.com/reference/android/text/DynamicLayout)after options have been set.                                                                                                                                                                               |
| ` static `[DynamicLayout.Builder](https://developer.android.com/reference/android/text/DynamicLayout.Builder) | ` `[obtain](https://developer.android.com/reference/android/text/DynamicLayout.Builder#obtain(java.lang.CharSequence,%20android.text.TextPaint,%20int))`(`[CharSequence](https://developer.android.com/reference/java/lang/CharSequence)` base, `[TextPaint](https://developer.android.com/reference/android/text/TextPaint)` paint, int width) ` Obtain a builder for constructing DynamicLayout objects. |
| ` `[DynamicLayout.Builder](https://developer.android.com/reference/android/text/DynamicLayout.Builder)        | ` `[setAlignment](https://developer.android.com/reference/android/text/DynamicLayout.Builder#setAlignment(android.text.Layout.Alignment))`(`[Layout.Alignment](https://developer.android.com/reference/android/text/Layout.Alignment)` alignment) ` Set the alignment.                                                                                                                                     |
| ` `[DynamicLayout.Builder](https://developer.android.com/reference/android/text/DynamicLayout.Builder)        | ` `[setBreakStrategy](https://developer.android.com/reference/android/text/DynamicLayout.Builder#setBreakStrategy(int))`(int breakStrategy) ` Set break strategy, useful for selecting high quality or balanced paragraph layout options.                                                                                                                                                                  |
| ` `[DynamicLayout.Builder](https://developer.android.com/reference/android/text/DynamicLayout.Builder)        | ` `[setDisplayText](https://developer.android.com/reference/android/text/DynamicLayout.Builder#setDisplayText(java.lang.CharSequence))`(`[CharSequence](https://developer.android.com/reference/java/lang/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](https://developer.android.com/reference/android/text/DynamicLayout.Builder)        | ` `[setEllipsize](https://developer.android.com/reference/android/text/DynamicLayout.Builder#setEllipsize(android.text.TextUtils.TruncateAt))`(`[TextUtils.TruncateAt](https://developer.android.com/reference/android/text/TextUtils.TruncateAt)` ellipsize) ` Set ellipsizing on the layout.                                                                                                             |
| ` `[DynamicLayout.Builder](https://developer.android.com/reference/android/text/DynamicLayout.Builder)        | ` `[setEllipsizedWidth](https://developer.android.com/reference/android/text/DynamicLayout.Builder#setEllipsizedWidth(int))`(int ellipsizedWidth) ` Set the width as used for ellipsizing purposes, if it differs from the normal layout width.                                                                                                                                                            |
| ` `[DynamicLayout.Builder](https://developer.android.com/reference/android/text/DynamicLayout.Builder)        | ` `[setHyphenationFrequency](https://developer.android.com/reference/android/text/DynamicLayout.Builder#setHyphenationFrequency(int))`(int hyphenationFrequency) ` Set hyphenation frequency, to control the amount of automatic hyphenation used.                                                                                                                                                         |
| ` `[DynamicLayout.Builder](https://developer.android.com/reference/android/text/DynamicLayout.Builder)        | ` `[setIncludePad](https://developer.android.com/reference/android/text/DynamicLayout.Builder#setIncludePad(boolean))`(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).                                                                                                          |
| ` `[DynamicLayout.Builder](https://developer.android.com/reference/android/text/DynamicLayout.Builder)        | ` `[setJustificationMode](https://developer.android.com/reference/android/text/DynamicLayout.Builder#setJustificationMode(int))`(int justificationMode) ` Set paragraph justification mode.                                                                                                                                                                                                                |
| ` `[DynamicLayout.Builder](https://developer.android.com/reference/android/text/DynamicLayout.Builder)        | ` `[setLineBreakConfig](https://developer.android.com/reference/android/text/DynamicLayout.Builder#setLineBreakConfig(android.graphics.text.LineBreakConfig))`(`[LineBreakConfig](https://developer.android.com/reference/android/graphics/text/LineBreakConfig)` lineBreakConfig) ` Set the line break configuration.                                                                                     |
| ` `[DynamicLayout.Builder](https://developer.android.com/reference/android/text/DynamicLayout.Builder)        | ` `[setLineSpacing](https://developer.android.com/reference/android/text/DynamicLayout.Builder#setLineSpacing(float,%20float))`(float spacingAdd, float spacingMult) ` Set line spacing parameters.                                                                                                                                                                                                        |
| ` `[DynamicLayout.Builder](https://developer.android.com/reference/android/text/DynamicLayout.Builder)        | ` `[setMinimumFontMetrics](https://developer.android.com/reference/android/text/DynamicLayout.Builder#setMinimumFontMetrics(android.graphics.Paint.FontMetrics))`(`[Paint.FontMetrics](https://developer.android.com/reference/android/graphics/Paint.FontMetrics)` minimumFontMetrics) ` Set the minimum font metrics used for line spacing.                                                              |
| ` `[DynamicLayout.Builder](https://developer.android.com/reference/android/text/DynamicLayout.Builder)        | ` `[setShiftDrawingOffsetForStartOverhang](https://developer.android.com/reference/android/text/DynamicLayout.Builder#setShiftDrawingOffsetForStartOverhang(boolean))`(boolean shiftDrawingOffsetForStartOverhang) ` Set true for shifting the drawing x offset for showing overhang at the start position.                                                                                                |
| ` `[DynamicLayout.Builder](https://developer.android.com/reference/android/text/DynamicLayout.Builder)        | ` `[setTextDirection](https://developer.android.com/reference/android/text/DynamicLayout.Builder#setTextDirection(android.text.TextDirectionHeuristic))`(`[TextDirectionHeuristic](https://developer.android.com/reference/android/text/TextDirectionHeuristic)` textDir) ` Set the text direction heuristic.                                                                                              |
| ` `[DynamicLayout.Builder](https://developer.android.com/reference/android/text/DynamicLayout.Builder)        | ` `[setUseBoundsForWidth](https://developer.android.com/reference/android/text/DynamicLayout.Builder#setUseBoundsForWidth(boolean))`(boolean useBoundsForWidth) ` Set true for using width of bounding box as a source of automatic line breaking and drawing.                                                                                                                                             |
| ` `[DynamicLayout.Builder](https://developer.android.com/reference/android/text/DynamicLayout.Builder)        | ` `[setUseLineSpacingFromFallbacks](https://developer.android.com/reference/android/text/DynamicLayout.Builder#setUseLineSpacingFromFallbacks(boolean))`(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).                   |

| ### Inherited methods |
|-----------------------|---|
| From class` `[java.lang.Object](https://developer.android.com/reference/java/lang/Object)` ` |--------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | ` `[Object](https://developer.android.com/reference/java/lang/Object)          | ` `[clone](https://developer.android.com/reference/java/lang/Object#clone())`() ` Creates and returns a copy of this object.                                                                                                                                                      | | ` boolean`                                                                     | ` `[equals](https://developer.android.com/reference/java/lang/Object#equals(java.lang.Object))`(`[Object](https://developer.android.com/reference/java/lang/Object)` obj) ` Indicates whether some other object is "equal to" this one.                                           | | ` void`                                                                        | ` `[finalize](https://developer.android.com/reference/java/lang/Object#finalize())`() ` Called by the garbage collector on an object when garbage collection determines that there are no more references to the object.                                                          | | ` final `[Class](https://developer.android.com/reference/java/lang/Class)`<?>` | ` `[getClass](https://developer.android.com/reference/java/lang/Object#getClass())`() ` Returns the runtime class of this`Object`.                                                                                                                                                | | ` int`                                                                         | ` `[hashCode](https://developer.android.com/reference/java/lang/Object#hashCode())`() ` Returns a hash code value for the object.                                                                                                                                                 | | ` final void`                                                                  | ` `[notify](https://developer.android.com/reference/java/lang/Object#notify())`() ` Wakes up a single thread that is waiting on this object's monitor.                                                                                                                            | | ` final void`                                                                  | ` `[notifyAll](https://developer.android.com/reference/java/lang/Object#notifyAll())`() ` Wakes up all threads that are waiting on this object's monitor.                                                                                                                         | | ` `[String](https://developer.android.com/reference/java/lang/String)          | ` `[toString](https://developer.android.com/reference/java/lang/Object#toString())`() ` Returns a string representation of the object.                                                                                                                                            | | ` final void`                                                                  | ` `[wait](https://developer.android.com/reference/java/lang/Object#wait(long,%20int))`(long timeoutMillis, int nanos) ` Causes the current thread to wait until it is awakened, typically by being*notified* or*interrupted*, or until a certain amount of real time has elapsed. | | ` final void`                                                                  | ` `[wait](https://developer.android.com/reference/java/lang/Object#wait(long))`(long timeoutMillis) ` Causes the current thread to wait until it is awakened, typically by being*notified* or*interrupted*, or until a certain amount of real time has elapsed.                   | | ` final void`                                                                  | ` `[wait](https://developer.android.com/reference/java/lang/Object#wait())`() ` Causes the current thread to wait until it is awakened, typically by being*notified* or*interrupted*.                                                                                             | ||

## Public methods

### build

Added in[API level 28](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public DynamicLayout build ()
```

Build the[DynamicLayout](https://developer.android.com/reference/android/text/DynamicLayout)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.

<br />

|                                                                                                                Returns                                                                                                                 ||
|-------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------|
| [DynamicLayout](https://developer.android.com/reference/android/text/DynamicLayout) | the newly constructed[DynamicLayout](https://developer.android.com/reference/android/text/DynamicLayout)object This value cannot be`null`. <br /> |

### obtain

Added in[API level 28](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

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

Obtain a builder for constructing DynamicLayout objects.

<br />

|                         Parameters                          ||
|---------|----------------------------------------------------|
| `base`  | `CharSequence`: This value cannot be`null`. <br /> |
| `paint` | `TextPaint`: This value cannot be`null`. <br />    |
| `width` | `int`: Value is 0 or greater <br />                |

|                                                                 Returns                                                                 ||
|-----------------------------------------------------------------------------------------------------|------------------------------------|
| [DynamicLayout.Builder](https://developer.android.com/reference/android/text/DynamicLayout.Builder) | This value cannot be`null`. <br /> |

### setAlignment

Added in[API level 28](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public DynamicLayout.Builder setAlignment (Layout.Alignment alignment)
```

Set the alignment. The default is[Layout.Alignment.ALIGN_NORMAL](https://developer.android.com/reference/android/text/Layout.Alignment#ALIGN_NORMAL).

<br />

|                                                                                    Parameters                                                                                     ||
|-------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `alignment` | `Layout.Alignment`: Alignment for the resulting[DynamicLayout](https://developer.android.com/reference/android/text/DynamicLayout)This value cannot be`null`. <br /> |

|                                                                                  Returns                                                                                  ||
|-----------------------------------------------------------------------------------------------------|----------------------------------------------------------------------|
| [DynamicLayout.Builder](https://developer.android.com/reference/android/text/DynamicLayout.Builder) | this builder, useful for chaining This value cannot be`null`. <br /> |

### setBreakStrategy

Added in[API level 28](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public DynamicLayout.Builder setBreakStrategy (int breakStrategy)
```

Set break strategy, useful for selecting high quality or balanced paragraph layout options. The default is[Layout.BREAK_STRATEGY_SIMPLE](https://developer.android.com/reference/android/text/Layout#BREAK_STRATEGY_SIMPLE).

<br />

|                                                                                                                                                                                                                                                  Parameters                                                                                                                                                                                                                                                  ||
|-----------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `breakStrategy` | `int`: break strategy for paragraph layout Value is[LineBreaker.BREAK_STRATEGY_SIMPLE](https://developer.android.com/reference/android/graphics/text/LineBreaker#BREAK_STRATEGY_SIMPLE),[LineBreaker.BREAK_STRATEGY_HIGH_QUALITY](https://developer.android.com/reference/android/graphics/text/LineBreaker#BREAK_STRATEGY_HIGH_QUALITY), or[LineBreaker.BREAK_STRATEGY_BALANCED](https://developer.android.com/reference/android/graphics/text/LineBreaker#BREAK_STRATEGY_BALANCED) <br /> |

|                                                                                  Returns                                                                                  ||
|-----------------------------------------------------------------------------------------------------|----------------------------------------------------------------------|
| [DynamicLayout.Builder](https://developer.android.com/reference/android/text/DynamicLayout.Builder) | this builder, useful for chaining This value cannot be`null`. <br /> |

**See also:**

- [TextView.setBreakStrategy(int)](https://developer.android.com/reference/android/widget/TextView#setBreakStrategy(int))  

### setDisplayText

Added in[API level 28](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public 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. The default is the 'base' text passed to the builder's constructor.

<br />

|                                     Parameters                                     ||
|-----------|-------------------------------------------------------------------------|
| `display` | `CharSequence`: the transformed text This value cannot be`null`. <br /> |

|                                                                                  Returns                                                                                  ||
|-----------------------------------------------------------------------------------------------------|----------------------------------------------------------------------|
| [DynamicLayout.Builder](https://developer.android.com/reference/android/text/DynamicLayout.Builder) | this builder, useful for chaining This value cannot be`null`. <br /> |

### setEllipsize

Added in[API level 28](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public DynamicLayout.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[TextUtils.TruncateAt.END](https://developer.android.com/reference/android/text/TextUtils.TruncateAt#END)or[TextUtils.TruncateAt.MARQUEE](https://developer.android.com/reference/android/text/TextUtils.TruncateAt#MARQUEE), to be ellipsized instead of broken. The default is`null`, indicating no ellipsis is to be applied.

<br />

|                                           Parameters                                           ||
|-------------|-----------------------------------------------------------------------------------|
| `ellipsize` | `TextUtils.TruncateAt`: type of ellipsis behavior This value may be`null`. <br /> |

|                                                                    Returns                                                                    ||
|-----------------------------------------------------------------------------------------------------|------------------------------------------|
| [DynamicLayout.Builder](https://developer.android.com/reference/android/text/DynamicLayout.Builder) | this builder, useful for chaining <br /> |

**See also:**

- [TextView.setEllipsize(TruncateAt)](https://developer.android.com/reference/android/widget/TextView#setEllipsize(android.text.TextUtils.TruncateAt))  

### setEllipsizedWidth

Added in[API level 28](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public DynamicLayout.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[obtain(CharSequence, TextPaint, int)](https://developer.android.com/reference/android/text/DynamicLayout.Builder#obtain(java.lang.CharSequence,%20android.text.TextPaint,%20int)).

<br />

|                                          Parameters                                          ||
|-------------------|---------------------------------------------------------------------------|
| `ellipsizedWidth` | `int`: width used for ellipsizing, in pixels Value is 0 or greater <br /> |

|                                                                                  Returns                                                                                  ||
|-----------------------------------------------------------------------------------------------------|----------------------------------------------------------------------|
| [DynamicLayout.Builder](https://developer.android.com/reference/android/text/DynamicLayout.Builder) | this builder, useful for chaining This value cannot be`null`. <br /> |

**See also:**

- [TextView.setEllipsize(TruncateAt)](https://developer.android.com/reference/android/widget/TextView#setEllipsize(android.text.TextUtils.TruncateAt))  

### setHyphenationFrequency

Added in[API level 28](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public DynamicLayout.Builder setHyphenationFrequency (int hyphenationFrequency)
```

Set hyphenation frequency, to control the amount of automatic hyphenation used. The possible values are defined in[Layout](https://developer.android.com/reference/android/text/Layout), by constants named with the pattern`HYPHENATION_FREQUENCY_*`. The default is[Layout.HYPHENATION_FREQUENCY_NONE](https://developer.android.com/reference/android/text/Layout#HYPHENATION_FREQUENCY_NONE).

<br />

|                                                                                                                                                                                                                                                                                                                                                                            Parameters                                                                                                                                                                                                                                                                                                                                                                            ||
|------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `hyphenationFrequency` | `int`: hyphenation frequency for the paragraph Value is[Layout.HYPHENATION_FREQUENCY_NORMAL](https://developer.android.com/reference/android/text/Layout#HYPHENATION_FREQUENCY_NORMAL),[Layout.HYPHENATION_FREQUENCY_NORMAL_FAST](https://developer.android.com/reference/android/text/Layout#HYPHENATION_FREQUENCY_NORMAL_FAST),[Layout.HYPHENATION_FREQUENCY_FULL](https://developer.android.com/reference/android/text/Layout#HYPHENATION_FREQUENCY_FULL),[Layout.HYPHENATION_FREQUENCY_FULL_FAST](https://developer.android.com/reference/android/text/Layout#HYPHENATION_FREQUENCY_FULL_FAST), or[Layout.HYPHENATION_FREQUENCY_NONE](https://developer.android.com/reference/android/text/Layout#HYPHENATION_FREQUENCY_NONE) <br /> |

|                                                                                  Returns                                                                                  ||
|-----------------------------------------------------------------------------------------------------|----------------------------------------------------------------------|
| [DynamicLayout.Builder](https://developer.android.com/reference/android/text/DynamicLayout.Builder) | this builder, useful for chaining This value cannot be`null`. <br /> |

**See also:**

- [TextView.setHyphenationFrequency(int)](https://developer.android.com/reference/android/widget/TextView#setHyphenationFrequency(int))  

### setIncludePad

Added in[API level 28](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

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

<br />

|                         Parameters                         ||
|--------------|----------------------------------------------|
| `includePad` | `boolean`: whether to include padding <br /> |

|                                                                                  Returns                                                                                  ||
|-----------------------------------------------------------------------------------------------------|----------------------------------------------------------------------|
| [DynamicLayout.Builder](https://developer.android.com/reference/android/text/DynamicLayout.Builder) | this builder, useful for chaining This value cannot be`null`. <br /> |

**See also:**

- [TextView.setIncludeFontPadding(boolean)](https://developer.android.com/reference/android/widget/TextView#setIncludeFontPadding(boolean))  

### setJustificationMode

Added in[API level 28](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public DynamicLayout.Builder setJustificationMode (int justificationMode)
```

Set paragraph justification mode. The default value is[Layout.JUSTIFICATION_MODE_NONE](https://developer.android.com/reference/android/text/Layout#JUSTIFICATION_MODE_NONE). If the last line is too short for justification, the last line will be displayed with the alignment set by[setAlignment(Alignment)](https://developer.android.com/reference/android/text/DynamicLayout.Builder#setAlignment(android.text.Layout.Alignment)).

<br />

|                                                                                                                                                                                                                                                                    Parameters                                                                                                                                                                                                                                                                    ||
|---------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `justificationMode` | `int`: justification mode for the paragraph. Value is[LineBreaker.JUSTIFICATION_MODE_NONE](https://developer.android.com/reference/android/graphics/text/LineBreaker#JUSTIFICATION_MODE_NONE),[LineBreaker.JUSTIFICATION_MODE_INTER_WORD](https://developer.android.com/reference/android/graphics/text/LineBreaker#JUSTIFICATION_MODE_INTER_WORD), or[LineBreaker.JUSTIFICATION_MODE_INTER_CHARACTER](https://developer.android.com/reference/android/graphics/text/LineBreaker#JUSTIFICATION_MODE_INTER_CHARACTER) <br /> |

|                                                                                  Returns                                                                                   ||
|-----------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------|
| [DynamicLayout.Builder](https://developer.android.com/reference/android/text/DynamicLayout.Builder) | this builder, useful for chaining. This value cannot be`null`. <br /> |

### setLineBreakConfig

Added in[API level 35](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public DynamicLayout.Builder setLineBreakConfig (LineBreakConfig lineBreakConfig)
```

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 is[LineBreakConfig.LINE_BREAK_STYLE_NONE](https://developer.android.com/reference/android/graphics/text/LineBreakConfig#LINE_BREAK_STYLE_NONE)

<br />

|                                                        Parameters                                                        ||
|-------------------|-------------------------------------------------------------------------------------------------------|
| `lineBreakConfig` | `LineBreakConfig`: the line break configuration for text wrapping. This value cannot be`null`. <br /> |

|                                                                                  Returns                                                                                   ||
|-----------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------|
| [DynamicLayout.Builder](https://developer.android.com/reference/android/text/DynamicLayout.Builder) | this builder, useful for chaining. This value cannot be`null`. <br /> |

**See also:**

- [TextView.setLineBreakStyle(int)](https://developer.android.com/reference/android/widget/TextView#setLineBreakStyle(int))
- [TextView.setLineBreakWordStyle(int)](https://developer.android.com/reference/android/widget/TextView#setLineBreakWordStyle(int))  

### setLineSpacing

Added in[API level 28](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public DynamicLayout.Builder setLineSpacing (float spacingAdd, 
                float spacingMult)
```

Set line spacing parameters. Each line will have its line spacing multiplied by`spacingMult`and then increased by`spacingAdd`. The default is 0.0 for`spacingAdd`and 1.0 for`spacingMult`.

<br />

|                                     Parameters                                      ||
|---------------|----------------------------------------------------------------------|
| `spacingAdd`  | `float`: the amount of line spacing addition <br />                  |
| `spacingMult` | `float`: the line spacing multiplier Value is 0.0f or greater <br /> |

|                                                                                  Returns                                                                                  ||
|-----------------------------------------------------------------------------------------------------|----------------------------------------------------------------------|
| [DynamicLayout.Builder](https://developer.android.com/reference/android/text/DynamicLayout.Builder) | this builder, useful for chaining This value cannot be`null`. <br /> |

**See also:**

- [TextView.setLineSpacing(float, float)](https://developer.android.com/reference/android/widget/TextView#setLineSpacing(float,%20float))  

### setMinimumFontMetrics

Added in[API level 35](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public DynamicLayout.Builder setMinimumFontMetrics (Paint.FontMetrics minimumFontMetrics)
```

Set the minimum font metrics used for line spacing.

`null`is the default value. If`null`is set or left as default, the font metrics obtained by[Paint.getFontMetricsForLocale(Paint.FontMetrics)](https://developer.android.com/reference/android/graphics/Paint#getFontMetricsForLocale(android.graphics.Paint.FontMetrics))is used.

The minimum meaning here is the minimum value of line spacing: maximum value of[Paint.ascent()](https://developer.android.com/reference/android/graphics/Paint#ascent()), minimum value of[Paint.descent()](https://developer.android.com/reference/android/graphics/Paint#descent()).

By setting this value, each line will have minimum line spacing regardless of the text rendered. For example, usually Japanese script has larger vertical metrics than Latin script. By setting the metrics obtained by[Paint.getFontMetricsForLocale(Paint.FontMetrics)](https://developer.android.com/reference/android/graphics/Paint#getFontMetricsForLocale(android.graphics.Paint.FontMetrics))for Japanese or leave it`null`if the Paint's locale is Japanese, the line spacing for Japanese is reserved if the text is an English text. If the vertical metrics of the text is larger than Japanese, for example Burmese, the bigger font metrics is used.

<br />

|                                                                                                                                              Parameters                                                                                                                                              ||
|----------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `minimumFontMetrics` | `Paint.FontMetrics`: A minimum font metrics. Passing`null`for using the value obtained by[Paint.getFontMetricsForLocale(Paint.FontMetrics)](https://developer.android.com/reference/android/graphics/Paint#getFontMetricsForLocale(android.graphics.Paint.FontMetrics)) <br /> |

|                                                   Returns                                                   ||
|-----------------------------------------------------------------------------------------------------|--------|
| [DynamicLayout.Builder](https://developer.android.com/reference/android/text/DynamicLayout.Builder) | <br /> |

**See also:**

- [TextView.setMinimumFontMetrics(Paint.FontMetrics)](https://developer.android.com/reference/android/widget/TextView#setMinimumFontMetrics(android.graphics.Paint.FontMetrics))
- [TextView.getMinimumFontMetrics()](https://developer.android.com/reference/android/widget/TextView#getMinimumFontMetrics())
- [Layout.getMinimumFontMetrics()](https://developer.android.com/reference/android/text/Layout#getMinimumFontMetrics())
- [Layout.Builder.setMinimumFontMetrics(Paint.FontMetrics)](https://developer.android.com/reference/android/text/Layout.Builder#setMinimumFontMetrics(android.graphics.Paint.FontMetrics))
- [StaticLayout.Builder.setMinimumFontMetrics(Paint.FontMetrics)](https://developer.android.com/reference/android/text/StaticLayout.Builder#setMinimumFontMetrics(android.graphics.Paint.FontMetrics))  

### setShiftDrawingOffsetForStartOverhang

Added in[API level 35](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public DynamicLayout.Builder setShiftDrawingOffsetForStartOverhang (boolean shiftDrawingOffsetForStartOverhang)
```

Set true for shifting the drawing x offset for showing overhang at the start position. This flag is ignored if the[Layout.getUseBoundsForWidth()](https://developer.android.com/reference/android/text/Layout#getUseBoundsForWidth())is false. If this value is false, the Layout draws text from the zero even if there is a glyph stroke in a region where the x coordinate is negative. If this value is true, the Layout draws text with shifting the x coordinate of the drawing bounding box. This value is false by default.

<br />

|                                                                                  Parameters                                                                                   ||
|--------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------|
| `shiftDrawingOffsetForStartOverhang` | `boolean`: true for shifting the drawing offset for showing the stroke that is in the region where the x coordinate is negative. <br /> |

|                                                                 Returns                                                                 ||
|-----------------------------------------------------------------------------------------------------|------------------------------------|
| [DynamicLayout.Builder](https://developer.android.com/reference/android/text/DynamicLayout.Builder) | This value cannot be`null`. <br /> |

**See also:**

- [setUseBoundsForWidth(boolean)](https://developer.android.com/reference/android/text/DynamicLayout.Builder#setUseBoundsForWidth(boolean))
- [Layout.getUseBoundsForWidth()](https://developer.android.com/reference/android/text/Layout#getUseBoundsForWidth())  

### setTextDirection

Added in[API level 28](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public DynamicLayout.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[TextDirectionHeuristics.FIRSTSTRONG_LTR](https://developer.android.com/reference/android/text/TextDirectionHeuristics#FIRSTSTRONG_LTR).

<br />

|                                                          Parameters                                                           ||
|-----------|--------------------------------------------------------------------------------------------------------------------|
| `textDir` | `TextDirectionHeuristic`: text direction heuristic for resolving bidi behavior. This value cannot be`null`. <br /> |

|                                                                                  Returns                                                                                  ||
|-----------------------------------------------------------------------------------------------------|----------------------------------------------------------------------|
| [DynamicLayout.Builder](https://developer.android.com/reference/android/text/DynamicLayout.Builder) | this builder, useful for chaining This value cannot be`null`. <br /> |

### setUseBoundsForWidth

Added in[API level 35](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public DynamicLayout.Builder setUseBoundsForWidth (boolean useBoundsForWidth)
```

Set true for using width of bounding box as a source of automatic line breaking and drawing. If this value is false, the Layout determines the drawing offset and automatic line breaking based on total advances. By setting true, use all joined glyph's bounding boxes as a source of text width. 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 Layout will reserve more spaces for drawing.

<br />

|                                       Parameters                                        ||
|---------------------|--------------------------------------------------------------------|
| `useBoundsForWidth` | `boolean`: True for using bounding box, false for advances. <br /> |

|                                                                            Returns                                                                            ||
|-----------------------------------------------------------------------------------------------------|----------------------------------------------------------|
| [DynamicLayout.Builder](https://developer.android.com/reference/android/text/DynamicLayout.Builder) | this builder instance This value cannot be`null`. <br /> |

**See also:**

- [Layout.getUseBoundsForWidth()](https://developer.android.com/reference/android/text/Layout#getUseBoundsForWidth())
- [Layout.Builder.setUseBoundsForWidth(boolean)](https://developer.android.com/reference/android/text/Layout.Builder#setUseBoundsForWidth(boolean))  

### setUseLineSpacingFromFallbacks

Added in[API level 28](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public DynamicLayout.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.

<br />

|                                               Parameters                                               ||
|-------------------------------|-------------------------------------------------------------------------|
| `useLineSpacingFromFallbacks` | `boolean`: whether to expand linespacing based on fallback fonts <br /> |

|                                                                                  Returns                                                                                  ||
|-----------------------------------------------------------------------------------------------------|----------------------------------------------------------------------|
| [DynamicLayout.Builder](https://developer.android.com/reference/android/text/DynamicLayout.Builder) | this builder, useful for chaining This value cannot be`null`. <br /> |