Layout
abstract class Layout
kotlin.Any | |
↳ | android.text.Layout |
A base class that manages text layout in visual elements on the screen.
For text that will be edited, use a DynamicLayout
, which will be updated as the text changes. For text that will not change, use a StaticLayout
.
Summary
Nested classes | |
---|---|
A builder class for Layout object. |
|
open |
Stores information about bidirectional (left-to-right or right-to-left) text within the layout of a line. |
abstract |
Strategy for determining whether a text segment is inside a rectangle area. |
Constants | |
---|---|
static Int |
Value for break strategy indicating balanced line breaking. |
static Int |
Value for break strategy indicating high quality line breaking, including automatic hyphenation and doing whole-paragraph optimization of line breaks. |
static Int |
Value for break strategy indicating simple line breaking. |
static Float | |
static Float | |
static Int | |
static Int | |
static Int |
Value for hyphenation frequency indicating the full amount of automatic hyphenation, typical in typography. |
static Int |
Value for hyphenation frequency indicating the full amount of automatic hyphenation with using faster algorithm. |
static Int |
Value for hyphenation frequency indicating no automatic hyphenation. |
static Int |
Value for hyphenation frequency indicating a light amount of automatic hyphenation, which is a conservative default. |
static Int |
Value for hyphenation frequency indicating a light amount of automatic hyphenation with using faster algorithm. |
static Int |
Value for justification mode indicating the text is justified by stretching letter spacing. |
static Int |
Value for justification mode indicating the text is justified by stretching word spacing. |
static Int |
Value for justification mode indicating no justification. |
Protected constructors | |
---|---|
Layout(text: CharSequence!, paint: TextPaint!, width: Int, align: Layout.Alignment!, spacingMult: Float, spacingAdd: Float) Subclasses of Layout use this constructor to set the display text, width, and other standard properties. |
Public methods | |
---|---|
open RectF |
Get an actual bounding box that draws text content. |
open Unit |
Draw this Layout on the specified Canvas. |
open Unit |
draw(canvas: Canvas!, selectionHighlight: Path!, selectionHighlightPaint: Paint!, cursorOffsetVertical: Int) Draw this Layout on the specified canvas, with the highlight path drawn between the background and the text. |
open Unit |
draw(canvas: Canvas, highlightPaths: MutableList<Path!>?, highlightPaints: MutableList<Paint!>?, selectionPath: Path?, selectionPaint: Paint?, cursorOffsetVertical: Int) Draw this layout on the specified canvas. |
open Unit |
drawBackground(canvas: Canvas) Draw background of this layout. |
open Unit |
Draw text part of this layout. |
open Unit |
fillCharacterBounds(start: Int, end: Int, bounds: FloatArray, boundsStart: Int) Return the characters' bounds in the given range. |
Layout.Alignment |
Returns the alignment used for creating this layout in pixels. |
abstract Int |
Returns the number of extra pixels of descent padding in the bottom line of the Layout. |
Int |
Return the break strategy used for creating this layout. |
open Unit |
getCursorPath(point: Int, dest: Path!, editingBuffer: CharSequence!) Fills in the specified Path with a representation of a cursor at the specified offset. |
open static Float |
getDesiredWidth(source: CharSequence!, paint: TextPaint!) Return how wide a layout must be in order to display the specified text with one line per paragraph. |
open static Float |
getDesiredWidth(source: CharSequence!, start: Int, end: Int, paint: TextPaint!) Return how wide a layout must be in order to display the specified text slice with one line per paragraph. |
abstract Int |
getEllipsisCount(line: Int) Returns the number of characters to be ellipsized away, or 0 if no ellipsis is to take place. |
abstract Int |
getEllipsisStart(line: Int) Return the offset of the first character to be ellipsized away, relative to the start of the line. |
TextUtils.TruncateAt? |
Return the ellipsize option used for creating this layout. |
open Int |
Return the width to which this layout is ellipsized. |
open Int |
Return the total height of this layout. |
Int |
Return the hyphenation frequency used for creating this layout. |
Int |
Return the justification mode used for creating this layout. |
IntArray? |
Return a copy of the left indents used for this layout. |
Int |
getLineAscent(line: Int) Get the ascent of the text on the specified line. |
Int |
getLineBaseline(line: Int) Return the vertical position of the baseline of the specified line. |
Int |
getLineBottom(line: Int) Return the vertical position of the bottom of the specified line. |
open Int |
getLineBottom(line: Int, includeLineSpacing: Boolean) Return the vertical position of the bottom of the specified line. |
open Int |
getLineBounds(line: Int, bounds: Rect!) Return the baseline for the specified line (0…getLineCount() - 1) If bounds is not null, return the top, left, right, bottom extents of the specified line in it. |
open LineBreakConfig |
Gets the |
abstract Boolean |
getLineContainsTab(line: Int) Returns whether the specified line contains one or more characters that need to be handled specially, like tabs. |
abstract Int |
Return the number of lines of text in this layout. |
abstract Int |
getLineDescent(line: Int) Return the descent of the specified line(0…getLineCount() - 1). |
abstract Layout.Directions! |
getLineDirections(line: Int) Returns the directional run information for the specified line. |
Int |
getLineEnd(line: Int) Return the text offset after the last character on the specified line. |
open Int |
getLineForOffset(offset: Int) Get the line number on which the specified text offset appears. |
open Int |
getLineForVertical(vertical: Int) Get the line number corresponding to the specified vertical position. |
open Float |
getLineLeft(line: Int) Get the leftmost position that should be exposed for horizontal scrolling on the specified line. |
open Int |
getLineLetterSpacingUnitCount(line: Int, includeTrailingWhitespace: Boolean) Returns the number of letter spacing unit in the line. |
open Float |
getLineMax(line: Int) Gets the unsigned horizontal extent of the specified line, including leading margin indent, but excluding trailing whitespace. |
open Float |
getLineRight(line: Int) Get the rightmost position that should be exposed for horizontal scrolling on the specified line. |
Float |
Returns the amount added to the line height. |
Float |
Returns the multiplier applied to the line height. |
abstract Int |
getLineStart(line: Int) Return the text offset of the beginning of the specified line ( 0…getLineCount()). |
abstract Int |
getLineTop(line: Int) Return the vertical position of the top of the specified line (0…getLineCount()). |
open Int |
getLineVisibleEnd(line: Int) Return the text offset after the last visible character (so whitespace is not counted) on the specified line. |
open Float |
getLineWidth(line: Int) Gets the unsigned horizontal extent of the specified line, including leading margin indent and trailing whitespace. |
Int |
Return the maximum lines allowed used for creating this layout. |
open Paint.FontMetrics? |
Get the minimum font metrics used for line spacing. |
open Int |
getOffsetForHorizontal(line: Int, horiz: Float) Get the character offset on the specified line whose position is closest to the specified horizontal position. |
open Int |
getOffsetToLeftOf(offset: Int) |
open Int |
getOffsetToRightOf(offset: Int) |
TextPaint |
getPaint() Return the paint used for creating this layout. |
Layout.Alignment! |
getParagraphAlignment(line: Int) Get the alignment of the specified paragraph, taking into account markup attached to it. |
abstract Int |
getParagraphDirection(line: Int) Returns the primary directionality of the paragraph containing the specified line, either 1 for left-to-right lines, or -1 for right-to-left lines (see |
Int |
getParagraphLeft(line: Int) Get the left edge of the specified paragraph, inset by left margins. |
Int |
getParagraphRight(line: Int) Get the right edge of the specified paragraph, inset by right margins. |
open Float |
getPrimaryHorizontal(offset: Int) Get the primary horizontal position for the specified text offset. |
open IntArray? |
getRangeForRect(area: RectF, segmentFinder: SegmentFinder, inclusionStrategy: Layout.TextInclusionStrategy) Finds the range of text which is inside the specified rectangle area. |
IntArray? |
Return a copy of the right indents used for this layout. |
open Float |
getSecondaryHorizontal(offset: Int) Get the secondary horizontal position for the specified text offset. |
open Unit |
getSelectionPath(start: Int, end: Int, dest: Path!) Fills in the specified Path with a representation of a highlight between the specified offsets. |
open Boolean |
Returns true if shifting drawing offset for start overhang. |
Float |
Returns the amount added to the line height. |
Float |
Returns the multiplier applied to the line height. |
CharSequence |
getText() Return the text used for creating this layout. |
TextDirectionHeuristic |
Returns the text direction heuristic used for creating this layout. |
abstract Int |
Returns the (negative) number of extra pixels of ascent padding in the top line of the Layout. |
open Boolean |
Returns true if using bounding box as a width, false for using advance as a width. |
Int |
getWidth() Return the width used for creating this layout in pixels. |
Unit |
increaseWidthTo(wid: Int) Increase the width of this layout to the specified width. |
open Boolean |
Return true if the fallback line space is enabled in this Layout. |
Boolean |
Returns true if this layout is created with increased line height. |
open Boolean |
isRtlCharAt(offset: Int) Returns true if the character at offset is right to left (RTL). |
Protected methods | |
---|---|
Boolean |
Properties | |
---|---|
static Layout.TextInclusionStrategy |
Strategy which considers a text segment to be inside a rectangle area if the segment bounds intersect the rectangle. |
static Layout.TextInclusionStrategy |
Strategy which considers a text segment to be inside a rectangle area if the segment bounds are completely contained within the rectangle. |
static Layout.TextInclusionStrategy |
Strategy which considers a text segment to be inside a rectangle area if the center of the segment bounds is inside the rectangle. |
Constants
BREAK_STRATEGY_BALANCED
static val BREAK_STRATEGY_BALANCED: Int
Value for break strategy indicating balanced line breaking. The breaks are chosen to make all lines as close to the same length as possible, including automatic hyphenation.
Value: 2
BREAK_STRATEGY_HIGH_QUALITY
static val BREAK_STRATEGY_HIGH_QUALITY: Int
Value for break strategy indicating high quality line breaking, including automatic hyphenation and doing whole-paragraph optimization of line breaks.
Value: 1
BREAK_STRATEGY_SIMPLE
static val BREAK_STRATEGY_SIMPLE: Int
Value for break strategy indicating simple line breaking. Automatic hyphens are not added (though soft hyphens are respected), and modifying text generally doesn't affect the layout before it (which yields a more consistent user experience when editing), but layout may not be the highest quality.
Value: 0
DEFAULT_LINESPACING_ADDITION
static val DEFAULT_LINESPACING_ADDITION: Float
Value: 0.0f
DEFAULT_LINESPACING_MULTIPLIER
static val DEFAULT_LINESPACING_MULTIPLIER: Float
Value: 1.0f
HYPHENATION_FREQUENCY_FULL
static val HYPHENATION_FREQUENCY_FULL: Int
Value for hyphenation frequency indicating the full amount of automatic hyphenation, typical in typography. Useful for running text and where it's important to put the maximum amount of text in a screen with limited space.
Value: 2
HYPHENATION_FREQUENCY_FULL_FAST
static val HYPHENATION_FREQUENCY_FULL_FAST: Int
Value for hyphenation frequency indicating the full amount of automatic hyphenation with using faster algorithm. This option is useful for running text and where it's important to put the maximum amount of text in a screen with limited space. To make text rendering faster with hyphenation, this algorithm ignores some hyphen character related typographic features, e.g. kerning.
Value: 4
HYPHENATION_FREQUENCY_NONE
static val HYPHENATION_FREQUENCY_NONE: Int
Value for hyphenation frequency indicating no automatic hyphenation. Useful for backward compatibility, and for cases where the automatic hyphenation algorithm results in incorrect hyphenation. Mid-word breaks may still happen when a word is wider than the layout and there is otherwise no valid break. Soft hyphens are ignored and will not be used as suggestions for potential line breaks.
Value: 0
HYPHENATION_FREQUENCY_NORMAL
static val HYPHENATION_FREQUENCY_NORMAL: Int
Value for hyphenation frequency indicating a light amount of automatic hyphenation, which is a conservative default. Useful for informal cases, such as short sentences or chat messages.
Value: 1
HYPHENATION_FREQUENCY_NORMAL_FAST
static val HYPHENATION_FREQUENCY_NORMAL_FAST: Int
Value for hyphenation frequency indicating a light amount of automatic hyphenation with using faster algorithm. This option is useful for informal cases, such as short sentences or chat messages. To make text rendering faster with hyphenation, this algorithm ignores some hyphen character related typographic features, e.g. kerning.
Value: 3
JUSTIFICATION_MODE_INTER_CHARACTER
static val JUSTIFICATION_MODE_INTER_CHARACTER: Int
Value for justification mode indicating the text is justified by stretching letter spacing.
Value: 2
JUSTIFICATION_MODE_INTER_WORD
static val JUSTIFICATION_MODE_INTER_WORD: Int
Value for justification mode indicating the text is justified by stretching word spacing.
Value: 1
JUSTIFICATION_MODE_NONE
static val JUSTIFICATION_MODE_NONE: Int
Value for justification mode indicating no justification.
Value: 0
Protected constructors
Layout
protected Layout(
text: CharSequence!,
paint: TextPaint!,
width: Int,
align: Layout.Alignment!,
spacingMult: Float,
spacingAdd: Float)
Subclasses of Layout use this constructor to set the display text, width, and other standard properties.
Parameters | |
---|---|
text |
CharSequence!: the text to render |
paint |
TextPaint!: the default paint for the layout. Styles can override various attributes of the paint. |
width |
Int: the wrapping width for the text. |
align |
Layout.Alignment!: whether to left, right, or center the text. Styles can override the alignment. |
spacingMult |
Float: factor by which to scale the font size to get the default line spacing |
spacingAdd |
Float: amount to add to the default line spacing |
Public methods
computeDrawingBoundingBox
open fun computeDrawingBoundingBox(): RectF
Get an actual bounding box that draws text content. Note that the RectF#top
and RectF#bottom
may be different from the Layout#getLineTop(int)
of the first line and Layout#getLineBottom(int)
of the last line. The line top and line bottom are calculated based on yMin/yMax or ascent/descent value of font file. On the other hand, the drawing bounding boxes are calculated based on actual glyphs used there.
Return | |
---|---|
RectF |
bounding rectangle This value cannot be null . |
draw
open fun draw(c: Canvas!): Unit
Draw this Layout on the specified Canvas. This API draws background first, then draws text on top of it.
draw
open fun draw(
canvas: Canvas!,
selectionHighlight: Path!,
selectionHighlightPaint: Paint!,
cursorOffsetVertical: Int
): Unit
Draw this Layout on the specified canvas, with the highlight path drawn between the background and the text.
Parameters | |
---|---|
canvas |
Canvas!: the canvas |
selectionHighlight |
Path!: the path of the selection highlight or cursor; can be null |
selectionHighlightPaint |
Paint!: the paint for the selection highlight |
cursorOffsetVertical |
Int: the amount to temporarily translate the canvas while rendering the highlight |
draw
open fun draw(
canvas: Canvas,
highlightPaths: MutableList<Path!>?,
highlightPaints: MutableList<Paint!>?,
selectionPath: Path?,
selectionPaint: Paint?,
cursorOffsetVertical: Int
): Unit
Draw this layout on the specified canvas. This API draws background first, then draws highlight paths on top of it, then draws selection or cursor, then finally draws text on top of it.
Parameters | |
---|---|
canvas |
Canvas: the canvas This value cannot be null . |
highlightPaths |
MutableList<Path!>?: the path of the highlights. The highlightPaths and highlightPaints must have the same length and aligned in the same order. For example, the paint of the n-th of the highlightPaths should be stored at the n-th of highlightPaints. This value may be null . |
highlightPaints |
MutableList<Paint!>?: the paints for the highlights. The highlightPaths and highlightPaints must have the same length and aligned in the same order. For example, the paint of the n-th of the highlightPaths should be stored at the n-th of highlightPaints. This value may be null . |
selectionPath |
Path?: the selection or cursor path This value may be null . |
selectionPaint |
Paint?: the paint for the selection or cursor. This value may be null . |
cursorOffsetVertical |
Int: the amount to temporarily translate the canvas while rendering the highlight |
See Also
drawBackground
open fun drawBackground(canvas: Canvas): Unit
Draw background of this layout. Different from draw(android.graphics.Canvas,java.util.List,java.util.List,android.graphics.Path,android.graphics.Paint,int)
API, this API only draws background, not drawing text, highlights or selections. The background here is drawn by LineBackgroundSpan
attached to the text.
Parameters | |
---|---|
canvas |
Canvas: the canvas This value cannot be null . |
drawText
open fun drawText(canvas: Canvas): Unit
Draw text part of this layout. Different from draw(android.graphics.Canvas,java.util.List,java.util.List,android.graphics.Path,android.graphics.Paint,int)
API, this API only draws text part, not drawing highlights, selections, or backgrounds.
Parameters | |
---|---|
canvas |
Canvas: the canvas This value cannot be null . |
fillCharacterBounds
open fun fillCharacterBounds(
start: Int,
end: Int,
bounds: FloatArray,
boundsStart: Int
): Unit
Return the characters' bounds in the given range. The bounds
array will be filled starting from boundsStart
(inclusive). The coordinates are in local text layout.
Parameters | |
---|---|
start |
Int: the start index to compute the character bounds, inclusive. Value is 0 or greater |
end |
Int: the end index to compute the character bounds, exclusive. Value is 0 or greater |
bounds |
FloatArray: the array to fill in the character bounds. The array is divided into segments of four where each index in that segment represents left, top, right and bottom of the character. This value cannot be null . |
boundsStart |
Int: the inclusive start index in the array to start filling in the values from. Value is 0 or greater |
Exceptions | |
---|---|
java.lang.IndexOutOfBoundsException |
if the range defined by start and end exceeds the range of the text, or bounds doesn't have enough space to store the result. |
java.lang.IllegalArgumentException |
if bounds is null. |
getAlignment
fun getAlignment(): Layout.Alignment
Returns the alignment used for creating this layout in pixels.
Return | |
---|---|
Layout.Alignment |
the alignment used for creating this layout. This value cannot be null . |
getBottomPadding
abstract fun getBottomPadding(): Int
Returns the number of extra pixels of descent padding in the bottom line of the Layout.
getBreakStrategy
fun getBreakStrategy(): Int
Return the break strategy used for creating this layout.
Return | |
---|---|
Int |
the break strategy used for creating this layout. Value is android.graphics.text.LineBreaker#BREAK_STRATEGY_SIMPLE , android.graphics.text.LineBreaker#BREAK_STRATEGY_HIGH_QUALITY , or android.graphics.text.LineBreaker#BREAK_STRATEGY_BALANCED |
getCursorPath
open fun getCursorPath(
point: Int,
dest: Path!,
editingBuffer: CharSequence!
): Unit
Fills in the specified Path with a representation of a cursor at the specified offset. This will often be a vertical line but can be multiple discontinuous lines in text with multiple directionalities.
getDesiredWidth
open static fun getDesiredWidth(
source: CharSequence!,
paint: TextPaint!
): Float
Return how wide a layout must be in order to display the specified text with one line per paragraph.
As of O, Uses TextDirectionHeuristics#FIRSTSTRONG_LTR
as the default text direction heuristics. In the earlier versions uses TextDirectionHeuristics#LTR
as the default.
getDesiredWidth
open static fun getDesiredWidth(
source: CharSequence!,
start: Int,
end: Int,
paint: TextPaint!
): Float
Return how wide a layout must be in order to display the specified text slice with one line per paragraph.
As of O, Uses TextDirectionHeuristics#FIRSTSTRONG_LTR
as the default text direction heuristics. In the earlier versions uses TextDirectionHeuristics#LTR
as the default.
getEllipsisCount
abstract fun getEllipsisCount(line: Int): Int
Returns the number of characters to be ellipsized away, or 0 if no ellipsis is to take place.
getEllipsisStart
abstract fun getEllipsisStart(line: Int): Int
Return the offset of the first character to be ellipsized away, relative to the start of the line. (So 0 if the beginning of the line is ellipsized, not getLineStart().)
getEllipsize
fun getEllipsize(): TextUtils.TruncateAt?
Return the ellipsize option used for creating this layout. May return null if no ellipsize option was selected.
Return | |
---|---|
TextUtils.TruncateAt? |
The ellipsize option used for creating this layout, or null if no ellipsize option was selected. |
getEllipsizedWidth
open fun getEllipsizedWidth(): Int
Return the width to which this layout is ellipsized. If no ellipsize is applied, the same amount of getWidth
is returned.
Return | |
---|---|
Int |
the amount of ellipsized width in pixels. Value is 0 or greater |
getHyphenationFrequency
fun getHyphenationFrequency(): Int
Return the hyphenation frequency used for creating this layout.
Return | |
---|---|
Int |
the hyphenation frequency used for creating this layout. Value is android.text.Layout#HYPHENATION_FREQUENCY_NORMAL , android.text.Layout#HYPHENATION_FREQUENCY_NORMAL_FAST , android.text.Layout#HYPHENATION_FREQUENCY_FULL , android.text.Layout#HYPHENATION_FREQUENCY_FULL_FAST , or android.text.Layout#HYPHENATION_FREQUENCY_NONE |
getJustificationMode
fun getJustificationMode(): Int
Return the justification mode used for creating this layout.
Return | |
---|---|
Int |
the justification mode used for creating this layout. Value is android.graphics.text.LineBreaker#JUSTIFICATION_MODE_NONE , android.graphics.text.LineBreaker#JUSTIFICATION_MODE_INTER_WORD , or android.graphics.text.LineBreaker#JUSTIFICATION_MODE_INTER_CHARACTER |
getLeftIndents
fun getLeftIndents(): IntArray?
Return a copy of the left indents used for this layout. May return null if no left indentation is applied.
Return | |
---|---|
IntArray? |
the array of left indents in pixels. |
getLineAscent
fun getLineAscent(line: Int): Int
Get the ascent of the text on the specified line. The return value is negative to match the Paint.ascent() convention.
getLineBaseline
fun getLineBaseline(line: Int): Int
Return the vertical position of the baseline of the specified line.
getLineBottom
fun getLineBottom(line: Int): Int
Return the vertical position of the bottom of the specified line.
getLineBottom
open fun getLineBottom(
line: Int,
includeLineSpacing: Boolean
): Int
Return the vertical position of the bottom of the specified line.
Parameters | |
---|---|
line |
Int: index of the line |
includeLineSpacing |
Boolean: whether to include the line spacing |
getLineBounds
open fun getLineBounds(
line: Int,
bounds: Rect!
): Int
Return the baseline for the specified line (0…getLineCount() - 1) If bounds is not null, return the top, left, right, bottom extents of the specified line in it.
Parameters | |
---|---|
line |
Int: which line to examine (0..getLineCount() - 1) |
bounds |
Rect!: Optional. If not null, it returns the extent of the line |
Return | |
---|---|
Int |
the Y-coordinate of the baseline |
getLineBreakConfig
open fun getLineBreakConfig(): LineBreakConfig
Gets the LineBreakConfig
used for creating this layout. Do not modify the returned object.
Return | |
---|---|
LineBreakConfig |
The line break config used for creating this layout. This value cannot be null . |
getLineContainsTab
abstract fun getLineContainsTab(line: Int): Boolean
Returns whether the specified line contains one or more characters that need to be handled specially, like tabs.
getLineCount
abstract fun getLineCount(): Int
Return the number of lines of text in this layout.
getLineDescent
abstract fun getLineDescent(line: Int): Int
Return the descent of the specified line(0…getLineCount() - 1).
getLineDirections
abstract fun getLineDirections(line: Int): Layout.Directions!
Returns the directional run information for the specified line. The array alternates counts of characters in left-to-right and right-to-left segments of the line.
NOTE: this is inadequate to support bidirectional text, and will change.
getLineEnd
fun getLineEnd(line: Int): Int
Return the text offset after the last character on the specified line.
getLineForOffset
open fun getLineForOffset(offset: Int): Int
Get the line number on which the specified text offset appears. If you ask for a position before 0, you get 0; if you ask for a position beyond the end of the text, you get the last line.
getLineForVertical
open fun getLineForVertical(vertical: Int): Int
Get the line number corresponding to the specified vertical position. If you ask for a position above 0, you get 0; if you ask for a position below the bottom of the text, you get the last line.
getLineLeft
open fun getLineLeft(line: Int): Float
Get the leftmost position that should be exposed for horizontal scrolling on the specified line.
getLineLetterSpacingUnitCount
open fun getLineLetterSpacingUnitCount(
line: Int,
includeTrailingWhitespace: Boolean
): Int
Returns the number of letter spacing unit in the line.
This API returns a number of letters that is a target of letter spacing. The letter spacing won't be added to the middle of the characters that are needed to be treated as a single, e.g., ligatured or conjunct form. Note that this value is different from the number of] grapheme clusters that is calculated by BreakIterator#getCharacterInstance(Locale)
. For example, if the "fi" is ligatured, the ligatured form is treated as single uni and letter spacing is not added, but it has two separate grapheme cluster.
This value is used for calculating the letter spacing amount for the justification because the letter spacing is applied between clusters. For example, if extra W
pixels needed to be filled by letter spacing, the amount of letter spacing to be applied is W
/(letter spacing unit count - 1) px.
Parameters | |
---|---|
line |
Int: the index of the line Value is 0 or greater |
includeTrailingWhitespace |
Boolean: whether to include trailing whitespace |
Return | |
---|---|
Int |
the number of cluster count in the line. Value is 0 or greater |
getLineMax
open fun getLineMax(line: Int): Float
Gets the unsigned horizontal extent of the specified line, including leading margin indent, but excluding trailing whitespace.
getLineRight
open fun getLineRight(line: Int): Float
Get the rightmost position that should be exposed for horizontal scrolling on the specified line.
getLineSpacingAmount
fun getLineSpacingAmount(): Float
Returns the amount added to the line height.
Return | |
---|---|
Float |
the line height additional amount. |
getLineSpacingMultiplier
fun getLineSpacingMultiplier(): Float
Returns the multiplier applied to the line height.
Return | |
---|---|
Float |
the line height multiplier. |
getLineStart
abstract fun getLineStart(line: Int): Int
Return the text offset of the beginning of the specified line ( 0…getLineCount()). If the specified line is equal to the line count, returns the length of the text.
getLineTop
abstract fun getLineTop(line: Int): Int
Return the vertical position of the top of the specified line (0…getLineCount()). If the specified line is equal to the line count, returns the bottom of the last line.
getLineVisibleEnd
open fun getLineVisibleEnd(line: Int): Int
Return the text offset after the last visible character (so whitespace is not counted) on the specified line.
getLineWidth
open fun getLineWidth(line: Int): Float
Gets the unsigned horizontal extent of the specified line, including leading margin indent and trailing whitespace.
getMaxLines
fun getMaxLines(): Int
Return the maximum lines allowed used for creating this layout. Note that this is not an actual line count of this layout. Use getLineCount()
for getting the actual line count of this layout.
Return | |
---|---|
Int |
the maximum lines allowed used for creating this layout. Value is 1 or greater |
getMinimumFontMetrics
open fun getMinimumFontMetrics(): Paint.FontMetrics?
Get the minimum font metrics used for line spacing.
Return | |
---|---|
Paint.FontMetrics? |
a minimum font metrics. null for using the value obtained by Paint#getFontMetricsForLocale(Paint.FontMetrics) |
See Also
android.widget.TextView#setMinimumFontMetrics(Paint.FontMetrics)
android.widget.TextView#getMinimumFontMetrics()
android.text.Layout.Builder#setMinimumFontMetrics(Paint.FontMetrics)
android.text.StaticLayout.Builder#setMinimumFontMetrics(Paint.FontMetrics)
android.text.DynamicLayout.Builder#setMinimumFontMetrics(Paint.FontMetrics)
getOffsetForHorizontal
open fun getOffsetForHorizontal(
line: Int,
horiz: Float
): Int
Get the character offset on the specified line whose position is closest to the specified horizontal position.
getPaint
fun getPaint(): TextPaint
Return the paint used for creating this layout. Do not modify the returned paint object. This paint object will still be used for drawing/measuring text.
Return | |
---|---|
TextPaint |
the paint used for creating this layout. This value cannot be null . |
getParagraphAlignment
fun getParagraphAlignment(line: Int): Layout.Alignment!
Get the alignment of the specified paragraph, taking into account markup attached to it.
getParagraphDirection
abstract fun getParagraphDirection(line: Int): Int
Returns the primary directionality of the paragraph containing the specified line, either 1 for left-to-right lines, or -1 for right-to-left lines (see DIR_LEFT_TO_RIGHT
, DIR_RIGHT_TO_LEFT
).
getParagraphLeft
fun getParagraphLeft(line: Int): Int
Get the left edge of the specified paragraph, inset by left margins.
getParagraphRight
fun getParagraphRight(line: Int): Int
Get the right edge of the specified paragraph, inset by right margins.
getPrimaryHorizontal
open fun getPrimaryHorizontal(offset: Int): Float
Get the primary horizontal position for the specified text offset. This is the location where a new character would be inserted in the paragraph's primary direction.
getRangeForRect
open fun getRangeForRect(
area: RectF,
segmentFinder: SegmentFinder,
inclusionStrategy: Layout.TextInclusionStrategy
): IntArray?
Finds the range of text which is inside the specified rectangle area. The start of the range is the start of the first text segment inside the area, and the end of the range is the end of the last text segment inside the area.
A text segment is considered to be inside the area according to the provided TextInclusionStrategy
. If a text segment spans multiple lines or multiple directional runs (e.g. a hyphenated word), the text segment is divided into pieces at the line and run breaks, then the text segment is considered to be inside the area if any of its pieces are inside the area.
The returned range may also include text segments which are not inside the specified area, if those text segments are in between text segments which are inside the area. For example, the returned range may be "segment1 segment2 segment3" if "segment1" and "segment3" are inside the area and "segment2" is not.
Parameters | |
---|---|
area |
RectF: area for which the text range will be found This value cannot be null . |
segmentFinder |
SegmentFinder: SegmentFinder for determining the ranges of text to be considered as a text segment This value cannot be null . |
inclusionStrategy |
Layout.TextInclusionStrategy: strategy for determining whether a text segment is inside the specified area This value cannot be null . |
Return | |
---|---|
IntArray? |
int array of size 2 containing the start (inclusive) and end (exclusive) character offsets of the text range, or null if there are no text segments inside the area |
getRightIndents
fun getRightIndents(): IntArray?
Return a copy of the right indents used for this layout. May return null if no right indentation is applied.
Return | |
---|---|
IntArray? |
the array of right indents in pixels. |
getSecondaryHorizontal
open fun getSecondaryHorizontal(offset: Int): Float
Get the secondary horizontal position for the specified text offset. This is the location where a new character would be inserted in the direction other than the paragraph's primary direction.
getSelectionPath
open fun getSelectionPath(
start: Int,
end: Int,
dest: Path!
): Unit
Fills in the specified Path with a representation of a highlight between the specified offsets. This will often be a rectangle or a potentially discontinuous set of rectangles. If the start and end are the same, the returned path is empty.
getShiftDrawingOffsetForStartOverhang
open fun getShiftDrawingOffsetForStartOverhang(): Boolean
Returns true if shifting drawing offset for start overhang.
Return | |
---|---|
Boolean |
True if shifting drawing offset for start overhang. |
See Also
getSpacingAdd
fun getSpacingAdd(): Float
Returns the amount added to the line height.
Return | |
---|---|
Float |
the line height additional amount. |
getSpacingMultiplier
fun getSpacingMultiplier(): Float
Returns the multiplier applied to the line height.
Return | |
---|---|
Float |
the line height multiplier. |
getText
fun getText(): CharSequence
Return the text used for creating this layout.
Return | |
---|---|
CharSequence |
the text used for creating this layout. This value cannot be null . |
getTextDirectionHeuristic
fun getTextDirectionHeuristic(): TextDirectionHeuristic
Returns the text direction heuristic used for creating this layout.
Return | |
---|---|
TextDirectionHeuristic |
the text direction heuristic used for creating this layout This value cannot be null . |
getTopPadding
abstract fun getTopPadding(): Int
Returns the (negative) number of extra pixels of ascent padding in the top line of the Layout.
getUseBoundsForWidth
open fun getUseBoundsForWidth(): Boolean
Returns true if using bounding box as a width, false for using advance as a width.
Return | |
---|---|
Boolean |
True if using bounding box for width, false if using advance for width. |
getWidth
fun getWidth(): Int
Return the width used for creating this layout in pixels.
Return | |
---|---|
Int |
the width used for creating this layout in pixels. Value is 0 or greater |
increaseWidthTo
fun increaseWidthTo(wid: Int): Unit
Increase the width of this layout to the specified width. Be careful to use this only when you know it is appropriate— it does not cause the text to reflow to use the full new width.
isFallbackLineSpacingEnabled
open fun isFallbackLineSpacingEnabled(): Boolean
Return true if the fallback line space is enabled in this Layout.
Return | |
---|---|
Boolean |
true if the fallback line space is enabled. Otherwise, returns false. |
isFontPaddingIncluded
fun isFontPaddingIncluded(): Boolean
Returns true if this layout is created with increased line height.
Return | |
---|---|
Boolean |
true if the layout is created with increased line height. |
isRtlCharAt
open fun isRtlCharAt(offset: Int): Boolean
Returns true if the character at offset is right to left (RTL).
Parameters | |
---|---|
offset |
Int: the offset |
Return | |
---|---|
Boolean |
true if the character is RTL, false if it is LTR |
Protected methods
Properties
INCLUSION_STRATEGY_ANY_OVERLAP
static val INCLUSION_STRATEGY_ANY_OVERLAP: Layout.TextInclusionStrategy
Strategy which considers a text segment to be inside a rectangle area if the segment bounds intersect the rectangle.
INCLUSION_STRATEGY_CONTAINS_ALL
static val INCLUSION_STRATEGY_CONTAINS_ALL: Layout.TextInclusionStrategy
Strategy which considers a text segment to be inside a rectangle area if the segment bounds are completely contained within the rectangle.
INCLUSION_STRATEGY_CONTAINS_CENTER
static val INCLUSION_STRATEGY_CONTAINS_CENTER: Layout.TextInclusionStrategy
Strategy which considers a text segment to be inside a rectangle area if the center of the segment bounds is inside the rectangle.