public static final class StaticLayout.Builder extends Object
obtain(java.lang.CharSequence, int, int, android.text.TextPaint, int)
with the required arguments (text, paint, and width),
then call setters for optional parameters, and finally build()
to build the StaticLayout object. Parameters not explicitly set will get
default values.Modifier and Type | Method and Description |
---|---|
StaticLayout |
build()
Build the
StaticLayout after options have been set. |
protected void |
finalize()
Called by the garbage collector on an object when garbage collection
determines that there are no more references to the object.
|
static StaticLayout.Builder |
obtain(CharSequence source,
int start,
int end,
TextPaint paint,
int width)
Obtain a builder for constructing StaticLayout objects
|
StaticLayout.Builder |
setAlignment(Layout.Alignment alignment)
Set the alignment.
|
StaticLayout.Builder |
setBreakStrategy(int breakStrategy)
Set break strategy, useful for selecting high quality or balanced paragraph
layout options.
|
StaticLayout.Builder |
setEllipsize(TextUtils.TruncateAt ellipsize)
Set ellipsizing on the layout.
|
StaticLayout.Builder |
setEllipsizedWidth(int ellipsizedWidth)
Set the width as used for ellipsizing purposes, if it differs from the
normal layout width.
|
StaticLayout.Builder |
setHyphenationFrequency(int hyphenationFrequency)
Set hyphenation frequency, to control the amount of automatic hyphenation used.
|
StaticLayout.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).
|
StaticLayout.Builder |
setIndents(int[] leftIndents,
int[] rightIndents)
Set indents.
|
StaticLayout.Builder |
setLineSpacing(float spacingAdd,
float spacingMult)
Set line spacing parameters.
|
StaticLayout.Builder |
setMaxLines(int maxLines)
Set maximum number of lines.
|
StaticLayout.Builder |
setPaint(TextPaint paint)
Set the paint.
|
StaticLayout.Builder |
setText(CharSequence source) |
StaticLayout.Builder |
setText(CharSequence source,
int start,
int end)
Set the text.
|
StaticLayout.Builder |
setTextDirection(TextDirectionHeuristic textDir)
Set the text direction heuristic.
|
StaticLayout.Builder |
setWidth(int width)
Set the width.
|
public static StaticLayout.Builder obtain(CharSequence source, int start, int end, TextPaint paint, int width)
source
- The text to be laid out, optionally with spansstart
- The index of the start of the textend
- The index + 1 of the end of the textpaint
- The base paint used for layoutwidth
- The width in pixelspublic StaticLayout.Builder setText(CharSequence source)
public StaticLayout.Builder setText(CharSequence source, int start, int end)
DynamicLayout
but not as part
of normal StaticLayout
usage.source
- The text to be laid out, optionally with spansstart
- The index of the start of the textend
- The index + 1 of the end of the textpublic StaticLayout.Builder setPaint(TextPaint paint)
paint
- The base paint used for layoutpublic StaticLayout.Builder setWidth(int width)
width
- The width in pixelspublic StaticLayout.Builder setAlignment(Layout.Alignment alignment)
Layout.Alignment.ALIGN_NORMAL
.alignment
- Alignment for the resulting StaticLayout
public StaticLayout.Builder setTextDirection(TextDirectionHeuristic textDir)
TextDirectionHeuristics.FIRSTSTRONG_LTR
.textDir
- text direction heuristic for resolving BiDi behavior.public StaticLayout.Builder setLineSpacing(float spacingAdd, float spacingMult)
spacingAdd
and 1.0 for spacingMult
.spacingAdd
- line spacing addspacingMult
- line spacing multiplierTextView.setLineSpacing(float, float)
public StaticLayout.Builder setIncludePad(boolean includePad)
true
.includePad
- whether to include paddingTextView.setIncludeFontPadding(boolean)
public StaticLayout.Builder setEllipsizedWidth(int ellipsizedWidth)
width
passed to obtain(java.lang.CharSequence, int, int, android.text.TextPaint, int)
.ellipsizedWidth
- width used for ellipsizing, in pixelsTextView.setEllipsize(android.text.TextUtils.TruncateAt)
public StaticLayout.Builder setEllipsize(TextUtils.TruncateAt ellipsize)
TextUtils.TruncateAt.END
or
TextUtils.TruncateAt.MARQUEE
, to be ellipsized instead
of broken. The default is
null
, indicating no ellipsis is to be applied.ellipsize
- type of ellipsis behaviorTextView.setEllipsize(android.text.TextUtils.TruncateAt)
public StaticLayout.Builder setMaxLines(int maxLines)
maxLines
- maximum number of lines in the layoutTextView.setMaxLines(int)
public StaticLayout.Builder setBreakStrategy(int breakStrategy)
Layout.BREAK_STRATEGY_SIMPLE
.breakStrategy
- break strategy for paragraph layoutTextView.setBreakStrategy(int)
public StaticLayout.Builder setHyphenationFrequency(int hyphenationFrequency)
Layout.HYPHENATION_FREQUENCY_NONE
.hyphenationFrequency
- hyphenation frequency for the paragraphTextView.setHyphenationFrequency(int)
public StaticLayout.Builder setIndents(int[] leftIndents, int[] rightIndents)
leftIndents
- array of indent values for left margin, in pixelsrightIndents
- array of indent values for right margin, in pixelspublic StaticLayout build()
StaticLayout
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.
StaticLayout
objectprotected void finalize() throws Throwable
Object
finalize
method to dispose of
system resources or to perform other cleanup.
The general contract of finalize
is that it is invoked
if and when the JavaTM virtual
machine has determined that there is no longer any
means by which this object can be accessed by any thread that has
not yet died, except as a result of an action taken by the
finalization of some other object or class which is ready to be
finalized. The finalize
method may take any action, including
making this object available again to other threads; the usual purpose
of finalize
, however, is to perform cleanup actions before
the object is irrevocably discarded. For example, the finalize method
for an object that represents an input/output connection might perform
explicit I/O transactions to break the connection before the object is
permanently discarded.
The finalize
method of class Object
performs no
special action; it simply returns normally. Subclasses of
Object
may override this definition.
The Java programming language does not guarantee which thread will
invoke the finalize
method for any given object. It is
guaranteed, however, that the thread that invokes finalize will not
be holding any user-visible synchronization locks when finalize is
invoked. If an uncaught exception is thrown by the finalize method,
the exception is ignored and finalization of that object terminates.
After the finalize
method has been invoked for an object, no
further action is taken until the Java virtual machine has again
determined that there is no longer any means by which this object can
be accessed by any thread that has not yet died, including possible
actions by other objects or classes which are ready to be finalized,
at which point the object may be discarded.
The finalize
method is never invoked more than once by a Java
virtual machine for any given object.
Any exception thrown by the finalize
method causes
the finalization of this object to be halted, but is otherwise
ignored.