Stay organized with collections
Save and categorize content based on your preferences.
MeasuredText
open class MeasuredText
Result of text shaping of the single paragraph string.
<code>
Paint paint = new Paint();
Paint bigPaint = new Paint();
bigPaint.setTextSize(paint.getTextSize() * 2.0);
String text = "Hello, Android.";
MeasuredText mt = new MeasuredText.Builder(text.toCharArray())
.appendStyleRun(paint, 7, false) // Use paint for "Hello, "
.appendStyleRun(bigPaint, 8, false) // Use bigPaint for "Android."
.build();
</code>
Summary
Public methods |
open Unit |
Retrieves the boundary box of the given range
|
open Float |
Returns the width of the character at the given offset.
|
open Unit |
Retrieves the font metrics of the given range
|
open Float |
Returns the width of a given range.
|
Public methods
getBounds
open fun getBounds(
start: Int,
end: Int,
rect: Rect
): Unit
Retrieves the boundary box of the given range
Parameters |
start |
Int: an inclusive start index of the range Value is 0 or greater |
end |
Int: an exclusive end index of the range Value is 0 or greater |
rect |
Rect: an output parameter This value cannot be null . |
getCharWidthAt
open fun getCharWidthAt(offset: Int): Float
Returns the width of the character at the given offset.
The units of this value are pixels.
Parameters |
offset |
Int: an offset of the character. Value is 0 or greater |
Return |
Float |
Value is 0.0f or greater The units of this value are pixels. {} |
getFontMetricsInt
open fun getFontMetricsInt(
start: Int,
end: Int,
outMetrics: Paint.FontMetricsInt
): Unit
Retrieves the font metrics of the given range
Parameters |
start |
Int: an inclusive start index of the range Value is 0 or greater |
end |
Int: an exclusive end index of the range Value is 0 or greater |
outMetrics |
Paint.FontMetricsInt: an output metrics object This value cannot be null . |
getWidth
open fun getWidth(
start: Int,
end: Int
): Float
Returns the width of a given range.
The units of this value are pixels.
Parameters |
start |
Int: an inclusive start index of the range Value is 0 or greater |
end |
Int: an exclusive end index of the range Value is 0 or greater |
Return |
Float |
Value is 0.0f or greater The units of this value are pixels. {} |
Content and code samples on this page are subject to the licenses described in the Content License. Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
Last updated 2025-08-20 UTC.
[null,null,["Last updated 2025-08-20 UTC."],[],[],null,["# MeasuredText\n\nAdded in [API level 29](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)\n\nMeasuredText\n============\n\n*** ** * ** ***\n\nKotlin \\|[Java](/reference/android/graphics/text/MeasuredText \"View this page in Java\") \n\n```\nopen class MeasuredText\n```\n\n|---|-----------------------------------------|\n| [kotlin.Any](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html) ||\n| ↳ | [android.graphics.text.MeasuredText](#) |\n\nResult of text shaping of the single paragraph string.\n\n```kotlin\n\u003ccode\u003e\n Paint paint = new Paint();\n Paint bigPaint = new Paint();\n bigPaint.setTextSize(paint.getTextSize() * 2.0);\n String text = \"Hello, Android.\";\n MeasuredText mt = new MeasuredText.Builder(text.toCharArray())\n .appendStyleRun(paint, 7, false) // Use paint for \"Hello, \"\n .appendStyleRun(bigPaint, 8, false) // Use bigPaint for \"Android.\"\n .build();\n \u003c/code\u003e\n```\n\n\u003cbr /\u003e\n\nSummary\n-------\n\n| Nested classes ||\n|---|------------------------------------------------------------------------------------------------------------------------|\n| | [Builder](/reference/kotlin/android/graphics/text/MeasuredText.Builder) Helper class for creating a [MeasuredText](#). |\n\n| Public methods ||\n|-------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| open [Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | [getBounds](#getBounds(kotlin.Int,%20kotlin.Int,%20android.graphics.Rect))`(`start:` `[Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html)`, `end:` `[Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html)`, `rect:` `[Rect](../Rect.html#)`)` Retrieves the boundary box of the given range |\n| open [Float](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-float/index.html) | [getCharWidthAt](#getCharWidthAt(kotlin.Int))`(`offset:` `[Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html)`)` Returns the width of the character at the given offset. |\n| open [Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | [getFontMetricsInt](#getFontMetricsInt(kotlin.Int,%20kotlin.Int,%20android.graphics.Paint.FontMetricsInt))`(`start:` `[Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html)`, `end:` `[Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html)`, `outMetrics:` `[Paint.FontMetricsInt](../Paint.FontMetricsInt.html#)`)` Retrieves the font metrics of the given range |\n| open [Float](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-float/index.html) | [getWidth](#getWidth(kotlin.Int,%20kotlin.Int))`(`start:` `[Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html)`, `end:` `[Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html)`)` Returns the width of a given range. |\n\nPublic methods\n--------------\n\n### getBounds\n\nAdded in [API level 29](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels) \n\n```\nopen fun getBounds(\n start: Int, \n end: Int, \n rect: Rect\n): Unit\n```\n\nRetrieves the boundary box of the given range\n\n| Parameters ||\n|---------|-----------------------------------------------------------------------------------------------------------------------------------------|\n| `start` | [Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html): an inclusive start index of the range Value is 0 or greater |\n| `end` | [Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html): an exclusive end index of the range Value is 0 or greater |\n| `rect` | [Rect](../Rect.html#): an output parameter This value cannot be `null`. |\n\n### getCharWidthAt\n\nAdded in [API level 29](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels) \n\n```\nopen fun getCharWidthAt(offset: Int): Float\n```\n\nReturns the width of the character at the given offset. \nThe units of this value are pixels.\n\n| Parameters ||\n|----------|-------------------------------------------------------------------------------------------------------------------------------|\n| `offset` | [Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html): an offset of the character. Value is 0 or greater |\n\n| Return ||\n|--------------------------------------------------------------------------------|-----------------------------------------------------------------|\n| [Float](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-float/index.html) | Value is 0.0f or greater The units of this value are pixels. {} |\n\n### getFontMetricsInt\n\nAdded in [API level 33](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels) \n\n```\nopen fun getFontMetricsInt(\n start: Int, \n end: Int, \n outMetrics: Paint.FontMetricsInt\n): Unit\n```\n\nRetrieves the font metrics of the given range\n\n| Parameters ||\n|--------------|-----------------------------------------------------------------------------------------------------------------------------------------|\n| `start` | [Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html): an inclusive start index of the range Value is 0 or greater |\n| `end` | [Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html): an exclusive end index of the range Value is 0 or greater |\n| `outMetrics` | [Paint.FontMetricsInt](../Paint.FontMetricsInt.html#): an output metrics object This value cannot be `null`. |\n\n### getWidth\n\nAdded in [API level 29](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels) \n\n```\nopen fun getWidth(\n start: Int, \n end: Int\n): Float\n```\n\nReturns the width of a given range. \nThe units of this value are pixels.\n\n| Parameters ||\n|---------|-----------------------------------------------------------------------------------------------------------------------------------------|\n| `start` | [Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html): an inclusive start index of the range Value is 0 or greater |\n| `end` | [Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html): an exclusive end index of the range Value is 0 or greater |\n\n| Return ||\n|--------------------------------------------------------------------------------|-----------------------------------------------------------------|\n| [Float](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-float/index.html) | Value is 0.0f or greater The units of this value are pixels. {} |"]]