java.lang.Object | |
↳ | android.text.StaticLayout.Builder |
Builder for static layouts. The builder is a newer pattern for constructing
StaticLayout objects and should be preferred over the constructors,
particularly to access newer features. To build a static layout, first
call obtain(CharSequence, int, int, 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.
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Build the
StaticLayout after options have been set.
| |||||||||||
Obtain a builder for constructing StaticLayout objects
| |||||||||||
Set the alignment.
| |||||||||||
Set break strategy, useful for selecting high quality or balanced paragraph
layout options.
| |||||||||||
Set ellipsizing on the layout.
| |||||||||||
Set the width as used for ellipsizing purposes, if it differs from the
normal layout width.
| |||||||||||
Set hyphenation frequency, to control the amount of automatic hyphenation used.
| |||||||||||
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).
| |||||||||||
Set indents.
| |||||||||||
Set line spacing parameters.
| |||||||||||
Set maximum number of lines.
| |||||||||||
Set the text direction heuristic.
|
Protected Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Invoked when the garbage collector has detected that this instance is no longer reachable.
|
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
java.lang.Object
|
Build the 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
object
Obtain a builder for constructing StaticLayout objects
source | The text to be laid out, optionally with spans |
---|---|
start | The index of the start of the text |
end | The index + 1 of the end of the text |
paint | The base paint used for layout |
width | The width in pixels |
Set the alignment. The default is ALIGN_NORMAL
.
alignment | Alignment for the resulting StaticLayout |
---|
Set break strategy, useful for selecting high quality or balanced paragraph
layout options. The default is BREAK_STRATEGY_SIMPLE
.
breakStrategy | break strategy for paragraph layout |
---|
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 END
or
MARQUEE
, to be ellipsized instead
of broken. The default is
null
, indicating no ellipsis is to be applied.
ellipsize | type of ellipsis behavior |
---|
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, int, int, TextPaint, int)
.
ellipsizedWidth | width used for ellipsizing, in pixels |
---|
Set hyphenation frequency, to control the amount of automatic hyphenation used. The
default is HYPHENATION_FREQUENCY_NONE
.
hyphenationFrequency | hyphenation frequency for the paragraph |
---|
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
.
includePad | whether to include padding |
---|
Set indents. Arguments are arrays holding an indent amount, one per line, measured in pixels. For lines past the last element in the array, the last element repeats.
leftIndents | array of indent values for left margin, in pixels |
---|---|
rightIndents | array of indent values for right margin, in pixels |
Set line spacing parameters. The default is 0.0 for spacingAdd
and 1.0 for spacingMult
.
spacingAdd | line spacing add |
---|---|
spacingMult | line spacing multiplier |
Set maximum number of lines. This is particularly useful in the case of ellipsizing, where it changes the layout of the last line. The default is unlimited.
maxLines | maximum number of lines in the layout |
---|
Set the text direction heuristic. The text direction heuristic is used to
resolve text direction based per-paragraph based on the input text. The default is
FIRSTSTRONG_LTR
.
textDir | text direction heuristic for resolving BiDi behavior. |
---|
Invoked when the garbage collector has detected that this instance is no longer reachable. The default implementation does nothing, but this method can be overridden to free resources.
Note that objects that override finalize
are significantly more expensive than
objects that don't. Finalizers may be run a long time after the object is no longer
reachable, depending on memory pressure, so it's a bad idea to rely on them for cleanup.
Note also that finalizers are run on a single VM-wide finalizer thread,
so doing blocking work in a finalizer is a bad idea. A finalizer is usually only necessary
for a class that has a native peer and needs to call a native method to destroy that peer.
Even then, it's better to provide an explicit close
method (and implement
Closeable
), and insist that callers manually dispose of instances. This
works well for something like files, but less well for something like a BigInteger
where typical calling code would have to deal with lots of temporaries. Unfortunately,
code that creates lots of temporaries is the worst kind of code from the point of view of
the single finalizer thread.
If you must use finalizers, consider at least providing your own
ReferenceQueue
and having your own thread process that queue.
Unlike constructors, finalizers are not automatically chained. You are responsible for
calling super.finalize()
yourself.
Uncaught exceptions thrown by finalizers are ignored and do not terminate the finalizer thread. See Effective Java Item 7, "Avoid finalizers" for more.
Throwable |
---|