# Print output for @column tags ?>
public
static
final
class
MeasuredText.Builder
extends Object
java.lang.Object | |
↳ | android.graphics.text.MeasuredText.Builder |
Helper class for creating a MeasuredText
.
Paint paint = new Paint();
String text = "Hello, Android.";
MeasuredText mt = new MeasuredText.Builder(text.toCharArray())
.appendStyleRun(paint, text.length, false)
.build();
Note: The appendStyle and appendReplacementRun should be called to cover the text length.
Public constructors | |
---|---|
Builder(char[] text)
Construct a builder. |
|
Builder(MeasuredText text)
Construct a builder with existing MeasuredText. |
Public methods | |
---|---|
MeasuredText.Builder
|
appendReplacementRun(Paint paint, int length, float width)
Used to inform the text layout that the given length is replaced with the object of given width. |
MeasuredText.Builder
|
appendStyleRun(Paint paint, int length, boolean isRtl)
Apply styles to the given length. |
MeasuredText
|
build()
Creates a MeasuredText. |
MeasuredText.Builder
|
setComputeHyphenation(boolean computeHyphenation)
By passing true to this method, the build method will compute all possible hyphenation pieces as well. |
MeasuredText.Builder
|
setComputeLayout(boolean computeLayout)
By passing true to this method, the build method will compute all full layout information. |
Inherited methods | |
---|---|
public Builder (char[] text)
Construct a builder. The MeasuredText returned by build method will hold a reference of the text. Developer is not supposed to modify the text.
Parameters | |
---|---|
text |
char : a text
This value cannot be null . |
public Builder (MeasuredText text)
Construct a builder with existing MeasuredText. The MeasuredText returned by build method will hold a reference of the text. Developer is not supposed to modify the text.
Parameters | |
---|---|
text |
MeasuredText : a text
This value cannot be null . |
public MeasuredText.Builder appendReplacementRun (Paint paint, int length, float width)
Used to inform the text layout that the given length is replaced with the object of given
width.
Keeps an internal offset which increases at every append. The initial value for this
offset is zero. After the style is applied the internal offset is moved to offset
+ length
, and next call will start from this new position.
Informs the layout engine that the given length should not be processed, instead the
provided width should be used for calculating the width of that range.
Parameters | |
---|---|
paint |
Paint : This value cannot be null . |
length |
int : a length to be replaced with the object, can not exceed the length of the
text
Value is 0 or greater |
width |
float : a replacement width of the range
This units of this value are pixels.
Value is 0 or greater |
Returns | |
---|---|
MeasuredText.Builder |
This value cannot be null . |
public MeasuredText.Builder appendStyleRun (Paint paint, int length, boolean isRtl)
Apply styles to the given length.
Keeps an internal offset which increases at every append. The initial value for this
offset is zero. After the style is applied the internal offset is moved to offset
+ length
, and next call will start from this new position.
Parameters | |
---|---|
paint |
Paint : a paint
This value cannot be null . |
length |
int : a length to be applied with a given paint, can not exceed the length of the
text
Value is 0 or greater |
isRtl |
boolean : true if the text is in RTL context, otherwise false. |
Returns | |
---|---|
MeasuredText.Builder |
This value cannot be null . |
public MeasuredText build ()
Creates a MeasuredText. Once you called build() method, you can't reuse the Builder class again.
Returns | |
---|---|
MeasuredText |
This value cannot be null . |
Throws | |
---|---|
IllegalStateException |
if this Builder is reused. |
IllegalStateException |
if the whole text is not covered by one or more runs (style or replacement) |
public MeasuredText.Builder setComputeHyphenation (boolean computeHyphenation)
By passing true to this method, the build method will compute all possible hyphenation pieces as well. If you don't want to use automatic hyphenation, you can pass false to this method and save the computation time of hyphenation. The default value is false. Even if you pass false to this method, you can still enable automatic hyphenation of LineBreaker but line break computation becomes slower.
Parameters | |
---|---|
computeHyphenation |
boolean : true if you want to use automatic hyphenations. |
Returns | |
---|---|
MeasuredText.Builder |
This value cannot be null . |
public MeasuredText.Builder setComputeLayout (boolean computeLayout)
By passing true to this method, the build method will compute all full layout
information.
If you don't use MeasuredText#getBounds(int,int,android.graphics.Rect)
, you can
pass false to this method and save the memory spaces. The default value is true.
Even if you pass false to this method, you can still call getBounds but it becomes
slower.
Parameters | |
---|---|
computeLayout |
boolean : true if you want to retrieve full layout info, e.g. bbox. |
Returns | |
---|---|
MeasuredText.Builder |
This value cannot be null . |