public class TextLayoutBuilder extends Object
Modifier and Type | Class and Description |
---|---|
static interface |
TextLayoutBuilder.MeasureMode
Measure mode constants similar to
View.MeasureSpec |
Modifier and Type | Field and Description |
---|---|
static int |
DEFAULT_MAX_LINES |
static int |
MEASURE_MODE_AT_MOST |
static int |
MEASURE_MODE_EXACTLY |
static int |
MEASURE_MODE_UNSPECIFIED |
Constructor and Description |
---|
TextLayoutBuilder() |
Modifier and Type | Method and Description |
---|---|
Layout |
build()
Builds and returns a
Layout . |
Layout.Alignment |
getAlignment()
Returns the text alignment for this TextLayoutBuilder.
|
int |
getBreakStrategy()
Returns the break strategy for this TextLayoutBuilder.
|
float |
getDensity() |
int[] |
getDrawableState()
Returns the drawable state for this TextLayoutBuilder.
|
TextUtils.TruncateAt |
getEllipsize()
Returns the text ellipsize for this TextLayoutBuilder.
|
GlyphWarmer |
getGlyphWarmer()
Returns the GlyphWarmer used by the TextLayoutBuilder.
|
int |
getHyphenationFrequency()
Returns the hyphenation frequency for this TextLayoutBuilder.
|
boolean |
getIncludeFontPadding()
Returns whether this TextLayoutBuilder should include font padding.
|
int[] |
getLeftIndents()
Returns the left indents set on this TextLayoutBuilder.
|
int |
getLinkColor()
Returns the link color for this TextLayoutBuilder.
|
int |
getMaxEms()
Returns the max width expressed in ems.
|
int |
getMaxLines()
Returns the number of max lines used by this TextLayoutBuilder.
|
int |
getMaxWidth()
Returns the max width expressed in pixels.
|
int |
getMinEms()
Returns the min width expressed in ems.
|
int |
getMinWidth()
Returns the min width expressed in pixels.
|
int[] |
getRightIndents()
Returns the right indents set on this TextLayoutBuilder.
|
boolean |
getShouldCacheLayout()
Returns whether the TextLayoutBuilder should cache the layout.
|
boolean |
getShouldWarmText()
Returns whether the TextLayoutBuilder should warm the layout.
|
boolean |
getSingleLine()
Returns whether the TextLayoutBuilder should show a single line.
|
CharSequence |
getText()
Returns the text that would be packed in a layout by this TextLayoutBuilder.
|
int |
getTextColor()
Returns the text color for this TextLayoutBuilder.
|
TextDirectionHeuristicCompat |
getTextDirection()
Returns the text direction for this TextLayoutBuilder.
|
float |
getTextSize()
Returns the text size for this TextLayoutBuilder.
|
float |
getTextSpacingExtra()
Returns the text spacing extra for this TextLayoutBuilder.
|
float |
getTextSpacingMultiplier()
Returns the text spacing multiplier for this TextLayoutBuilder.
|
Typeface |
getTypeface()
Returns the typeface for this TextLayoutBuilder.
|
TextLayoutBuilder |
setAlignment(Layout.Alignment alignment)
Sets text alignment for the layout.
|
TextLayoutBuilder |
setBreakStrategy(int breakStrategy)
Sets a break strategy breaking paragraphs into lines.
|
TextLayoutBuilder |
setDensity(float density)
Sets the density of this layout.
|
TextLayoutBuilder |
setDrawableState(int[] drawableState)
Updates the text colors based on the drawable state.
|
TextLayoutBuilder |
setEllipsize(TextUtils.TruncateAt ellipsize)
Sets the ellipsis location for the layout.
|
TextLayoutBuilder |
setGlyphWarmer(GlyphWarmer glyphWarmer)
Sets the glyph warmer to use.
|
TextLayoutBuilder |
setHyphenationFrequency(int hyphenationFrequency)
Sets the frequency of automatic hyphenation to use when determining word breaks.
|
TextLayoutBuilder |
setIncludeFontPadding(boolean shouldInclude)
Set whether the text Layout includes extra top and bottom padding to make
room for accents that go above the normal ascent and descent.
|
TextLayoutBuilder |
setIndents(int[] leftIndents,
int[] rightIndents)
Sets the left and right indents for this TextLayoutBuilder.
|
TextLayoutBuilder |
setLinkColor(int linkColor)
Sets the link color for the text in the layout.
|
TextLayoutBuilder |
setMaxEms(int maxEms)
Sets the max width expressed in ems.
|
TextLayoutBuilder |
setMaxLines(int maxLines)
Sets a maximum number of lines to be shown by the Layout.
|
TextLayoutBuilder |
setMaxWidth(int maxWidth)
Sets the max width expressed in pixels.
|
TextLayoutBuilder |
setMinEms(int minEms)
Sets the min width expressed in ems.
|
TextLayoutBuilder |
setMinWidth(int minWidth)
Sets the min width expressed in pixels.
|
TextLayoutBuilder |
setShadowLayer(float radius,
float dx,
float dy,
int color)
Sets the shadow layer for the layout.
|
TextLayoutBuilder |
setShouldCacheLayout(boolean shouldCacheLayout)
Sets whether the text layout should be cached or not.
|
TextLayoutBuilder |
setShouldWarmText(boolean shouldWarmText)
Sets whether the text should be warmed or not.
|
TextLayoutBuilder |
setSingleLine(boolean singleLine)
Sets whether the text should be in a single line or not.
|
TextLayoutBuilder |
setText(CharSequence text)
Sets the text for the layout.
|
TextLayoutBuilder |
setTextColor(ColorStateList colorStateList)
Sets the text color for the layout.
|
TextLayoutBuilder |
setTextColor(int color)
Sets the text color for the layout.
|
TextLayoutBuilder |
setTextDirection(TextDirectionHeuristicCompat textDirection)
Sets the text direction heuristic for the layout.
|
TextLayoutBuilder |
setTextSize(int size)
Sets the text size for the layout.
|
TextLayoutBuilder |
setTextSpacingExtra(float spacingExtra)
Sets the text extra spacing for the layout.
|
TextLayoutBuilder |
setTextSpacingMultiplier(float spacingMultiplier)
Sets the line spacing multiplier for the layout.
|
TextLayoutBuilder |
setTextStyle(int style)
Sets a text style for the layout.
|
TextLayoutBuilder |
setTypeface(Typeface typeface)
Sets the typeface used by this TextLayoutBuilder.
|
TextLayoutBuilder |
setWidth(int width)
Sets the intended width of the text layout.
|
TextLayoutBuilder |
setWidth(int width,
int measureMode)
Sets the intended width of the text layout while respecting the measure mode.
|
public static final int MEASURE_MODE_UNSPECIFIED
public static final int MEASURE_MODE_EXACTLY
public static final int MEASURE_MODE_AT_MOST
public static final int DEFAULT_MAX_LINES
public TextLayoutBuilder setWidth(int width)
width
- The width of the text layoutTextLayoutBuilder
instancesetWidth(int, int)
public TextLayoutBuilder setWidth(int width, int measureMode)
width
- The width of the text layoutmeasureMode
- The mode with which to treat the given widthTextLayoutBuilder
instancesetWidth(int)
public CharSequence getText()
public TextLayoutBuilder setText(CharSequence text)
text
- The text for the layoutTextLayoutBuilder
instancepublic float getTextSize()
public TextLayoutBuilder setTextSize(int size)
size
- The text size in pixelsTextLayoutBuilder
instancepublic int getTextColor()
public TextLayoutBuilder setTextColor(int color)
color
- The text color for the layoutTextLayoutBuilder
instancepublic TextLayoutBuilder setTextColor(ColorStateList colorStateList)
colorStateList
- The text color state list for the layoutTextLayoutBuilder
instancepublic int getLinkColor()
public TextLayoutBuilder setLinkColor(int linkColor)
linkColor
- The link colorTextLayoutBuilder
instancepublic float getTextSpacingExtra()
public TextLayoutBuilder setTextSpacingExtra(float spacingExtra)
spacingExtra
- the extra space that is added to the height of each lineTextLayoutBuilder
instancepublic float getTextSpacingMultiplier()
public TextLayoutBuilder setTextSpacingMultiplier(float spacingMultiplier)
spacingMultiplier
- the value by which each line's height is multipliedTextLayoutBuilder
instancepublic boolean getIncludeFontPadding()
public TextLayoutBuilder setIncludeFontPadding(boolean shouldInclude)
The default is true.
shouldInclude
- Whether to include font padding or notTextLayoutBuilder
instancepublic Layout.Alignment getAlignment()
public TextLayoutBuilder setAlignment(Layout.Alignment alignment)
alignment
- The text alignment for the layoutTextLayoutBuilder
instancepublic TextDirectionHeuristicCompat getTextDirection()
public TextLayoutBuilder setTextDirection(TextDirectionHeuristicCompat textDirection)
TextDirectionHeuristicCompat describes how to evaluate the text of this Layout to know whether to use RTL or LTR text direction
textDirection
- The text direction heuristic for the layoutTextLayoutBuilder
instancepublic TextLayoutBuilder setShadowLayer(float radius, float dx, float dy, int color)
radius
- The radius of the blur for shadowdx
- The horizontal translation of the origindy
- The vertical translation of the origincolor
- The shadow colorTextLayoutBuilder
instancepublic TextLayoutBuilder setTextStyle(int style)
style
- The text style for the layoutTextLayoutBuilder
instancepublic Typeface getTypeface()
public TextLayoutBuilder setTypeface(Typeface typeface)
typeface
- The typeface for this TextLayoutBuilderTextLayoutBuilder
instancepublic int[] getDrawableState()
public TextLayoutBuilder setDrawableState(int[] drawableState)
drawableState
- The current drawable state of the View holding this layoutTextLayoutBuilder
instancepublic TextUtils.TruncateAt getEllipsize()
public TextLayoutBuilder setEllipsize(TextUtils.TruncateAt ellipsize)
ellipsize
- The ellipsis location in the layoutTextLayoutBuilder
instancepublic boolean getSingleLine()
public TextLayoutBuilder setSingleLine(boolean singleLine)
singleLine
- Whether the text should be in a single line or notTextLayoutBuilder
instancesetMaxLines(int)
public int getMaxLines()
public TextLayoutBuilder setMaxLines(int maxLines)
Note: Gingerbread always default to two lines max when ellipsized. This cannot be changed. Use a TextView if you want more control over the number of lines.
maxLines
- The number of maxLines to show in this LayoutTextLayoutBuilder
instancesetSingleLine(boolean)
public int getBreakStrategy()
public TextLayoutBuilder setBreakStrategy(int breakStrategy)
breakStrategy
- The break strategy for breaking paragraphs into linesTextLayoutBuilder
instancepublic int getHyphenationFrequency()
public TextLayoutBuilder setHyphenationFrequency(int hyphenationFrequency)
hyphenationFrequency
- The frequency of automatic hyphenation to use for word breaksTextLayoutBuilder
instancepublic int[] getLeftIndents()
public int[] getRightIndents()
public TextLayoutBuilder setIndents(int[] leftIndents, int[] rightIndents)
The arrays hold an indent amount, one per line, measured in pixels. For lines past the last element in the array, the last element repeats.
leftIndents
- The left indents for the paragraphrightIndents
- The left indents for the paragraphTextLayoutBuilder
instancepublic boolean getShouldCacheLayout()
public TextLayoutBuilder setShouldCacheLayout(boolean shouldCacheLayout)
Note: If the Layout contains ClickableSpan
s, the layout will not be cached.
shouldCacheLayout
- True to cache the text layout, false otherwiseTextLayoutBuilder
instancepublic boolean getShouldWarmText()
public TextLayoutBuilder setShouldWarmText(boolean shouldWarmText)
Note: Setting this true is highly effective for large blurbs of text. This method has to be called before the draw pass.
shouldWarmText
- True to warm the text layout, false otherwiseTextLayoutBuilder
instancesetGlyphWarmer(GlyphWarmer)
public GlyphWarmer getGlyphWarmer()
public TextLayoutBuilder setGlyphWarmer(GlyphWarmer glyphWarmer)
glyphWarmer
- GlyphWarmer to use to warm the text layoutTextLayoutBuilder
instancesetShouldWarmText(boolean)
public int getMinEms()
setMinEms(int)
public TextLayoutBuilder setMinEms(int minEms)
minEms
- min width expressed in emsTextLayoutBuilder
instancesetMaxEms(int)
,
setMinWidth(int)
public int getMinWidth()
setMinWidth(int)
public TextLayoutBuilder setMinWidth(int minWidth)
minWidth
- min width expressed in pixels.TextLayoutBuilder
instancesetMaxWidth(int)
,
setMinEms(int)
public int getMaxEms()
setMaxEms(int)
public TextLayoutBuilder setMaxEms(int maxEms)
maxEms
- max width expressed in emsTextLayoutBuilder
instancesetMaxWidth(int)
,
setMinEms(int)
public int getMaxWidth()
setMaxWidth(int)
public TextLayoutBuilder setMaxWidth(int maxWidth)
maxWidth
- max width expressed in pixelsTextLayoutBuilder
instancesetMaxEms(int)
,
setMinWidth(int)
public float getDensity()
public TextLayoutBuilder setDensity(float density)
density
- The density desiredTextLayoutBuilder