Class DynamicLayout.Builder

java.lang.Object
icyllis.modernui.text.DynamicLayout.Builder
Enclosing class:
DynamicLayout

public static final class DynamicLayout.Builder extends Object
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 DynamicLayout.builder(java.lang.CharSequence, icyllis.modernui.text.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.
  • Method Details

    • setDisplayText

      @Nonnull public DynamicLayout.Builder setDisplayText(@Nonnull 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.
      Parameters:
      display - the transformed text
      Returns:
      this builder, useful for chaining
    • setAlignment

      @Nonnull public DynamicLayout.Builder setAlignment(@Nonnull Layout.Alignment alignment)
      Set the alignment. The default is Layout.Alignment.ALIGN_NORMAL.
      Parameters:
      alignment - Alignment for the resulting DynamicLayout
      Returns:
      this builder, useful for chaining
    • setTextDirection

      @Nonnull public DynamicLayout.Builder setTextDirection(@Nonnull 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.
      Parameters:
      textDir - text direction heuristic for resolving bidi behavior.
      Returns:
      this builder, useful for chaining
    • setIncludePad

      @Nonnull 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.
      Parameters:
      includePad - whether to include padding
      Returns:
      this builder, useful for chaining
    • setFallbackLineSpacing

      @Nonnull public DynamicLayout.Builder 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). 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

      @Nonnull 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 build().
      Parameters:
      ellipsizedWidth - width used for ellipsizing, in pixels
      Returns:
      this builder, useful for chaining
    • setEllipsize

      public DynamicLayout.Builder setEllipsize(@Nullable 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 or TextUtils.TruncateAt.MARQUEE, 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
    • build

      @Nonnull public DynamicLayout build()
      Build the 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.

      Returns:
      the newly constructed DynamicLayout object