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 |
|
|---|---|
| open |
Stores information about bidirectional (left-to-right or right-to-left) text within the layout of a line. |
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 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 justification mode indicating the text is justified by stretching word spacing. |
| static Int |
Value for justification mode indicating no justification. |
Protected constructors |
|
|---|---|
<init>(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 Unit |
Draw this Layout on the specified Canvas. |
| open Unit |
Draw this Layout on the specified canvas, with the highlight path drawn between the background and the text. |
| Layout.Alignment! |
Return the base alignment of this layout. |
| abstract Int |
Returns the number of extra pixels of descent padding in the bottom line of the 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. |
| open Int |
Return the width to which this Layout is ellipsizing, or |
| open Int |
Return the total height of 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 |
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. |
| 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 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. |
| 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. |
| 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 base Paint properties for 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 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. |
| Float |
Return the number of units of leading that are added to each line. |
| Float |
Return what the text height is multiplied by to get the line height. |
| CharSequence! |
getText()Return the text that is displayed by this Layout. |
| abstract Int |
Returns the (negative) number of extra pixels of ascent padding in the top line of the Layout. |
| Int |
getWidth()Return the width of this layout. |
| Unit |
increaseWidthTo(wid: Int)Increase the width of this layout to the specified width. |
| open Boolean |
isRtlCharAt(offset: Int)Returns true if the character at offset is right to left (RTL). |
Protected methods |
|
|---|---|
| Boolean | |
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_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
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
<init>
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
draw
open fun draw(
canvas: Canvas!,
highlight: Path!,
highlightPaint: 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 |
highlight |
Path!: the path of the highlight or cursor; can be null |
highlightPaint |
Paint!: the paint for the highlight |
cursorOffsetVertical |
Int: the amount to temporarily translate the canvas while rendering the highlight |
getAlignment
fun getAlignment(): Layout.Alignment!
Return the base alignment of this layout.
getBottomPadding
abstract fun getBottomPadding(): Int
Returns the number of extra pixels of descent padding in the bottom line of the Layout.
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().)
getEllipsizedWidth
open fun getEllipsizedWidth(): Int
Return the width to which this Layout is ellipsizing, or getWidth if it is not doing anything special.
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.
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 |
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.
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.
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.
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 base Paint properties for this layout. Do NOT change the paint, which may result in funny drawing for this layout.
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.
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.
getSpacingAdd
fun getSpacingAdd(): Float
Return the number of units of leading that are added to each line.
getSpacingMultiplier
fun getSpacingMultiplier(): Float
Return what the text height is multiplied by to get the line height.
getText
fun getText(): CharSequence!
Return the text that is displayed by this Layout.
getTopPadding
abstract fun getTopPadding(): Int
Returns the (negative) number of extra pixels of ascent padding in the top line of the Layout.
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.
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 |