DrawableMarginSpan
open class DrawableMarginSpan : LeadingMarginSpan, LineHeightSpan
kotlin.Any | |
↳ | android.text.style.DrawableMarginSpan |
A span which adds a drawable and a padding to the paragraph it's attached to.
If the height of the drawable is bigger than the height of the line it's attached to then the line height is increased to fit the drawable. DrawableMarginSpan
allows setting a padding between the drawable and the text. The default value is 0. The span must be set from the beginning of the text, otherwise either the span won't be rendered or it will be rendered incorrectly.
For example, a drawable and a padding of 20px can be added like this:
<code>SpannableString string = new SpannableString("Text with a drawable."); string.setSpan(new DrawableMarginSpan(drawable, 20), 0, string.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);</code>
Summary
Public constructors | |
---|---|
DrawableMarginSpan(drawable: Drawable) Creates a |
|
DrawableMarginSpan(drawable: Drawable, pad: Int) Creates a |
Public methods | |
---|---|
open Unit |
chooseHeight(text: CharSequence, start: Int, end: Int, istartv: Int, v: Int, fm: Paint.FontMetricsInt) Classes that implement this should define how the height is being calculated. |
open Unit |
drawLeadingMargin(c: Canvas, p: Paint, x: Int, dir: Int, top: Int, baseline: Int, bottom: Int, text: CharSequence, start: Int, end: Int, first: Boolean, layout: Layout) Renders the leading margin. |
open Drawable |
Returns the drawable used. |
open Int |
getLeadingMargin(first: Boolean) |
open Int |
Returns a distance between the drawable and text in pixel. |
open String |
toString() |
Public constructors
DrawableMarginSpan
DrawableMarginSpan(drawable: Drawable)
Creates a DrawableMarginSpan
from a Drawable
. The pad width will be 0.
Parameters | |
---|---|
drawable |
Drawable: the drawable to be added This value cannot be null . |
DrawableMarginSpan
DrawableMarginSpan(
drawable: Drawable,
pad: Int)
Creates a DrawableMarginSpan
from a Drawable
and a padding, in pixels.
Parameters | |
---|---|
drawable |
Drawable: the drawable to be added This value cannot be null . |
pad |
Int: the distance between the drawable and the text |
Public methods
chooseHeight
open fun chooseHeight(
text: CharSequence,
start: Int,
end: Int,
istartv: Int,
v: Int,
fm: Paint.FontMetricsInt
): Unit
Classes that implement this should define how the height is being calculated.
Parameters | |
---|---|
text |
CharSequence: This value cannot be null . |
start |
Int: the start of the line |
end |
Int: the end of the line |
spanstartv |
the start of the span |
lineHeight |
the line height |
fm |
Paint.FontMetricsInt: This value cannot be null . |
drawLeadingMargin
open fun drawLeadingMargin(
c: Canvas,
p: Paint,
x: Int,
dir: Int,
top: Int,
baseline: Int,
bottom: Int,
text: CharSequence,
start: Int,
end: Int,
first: Boolean,
layout: Layout
): Unit
Renders the leading margin. This is called before the margin has been adjusted by the value returned by getLeadingMargin(boolean)
.
Parameters | |
---|---|
c |
Canvas: This value cannot be null . |
p |
Paint: This value cannot be null . |
x |
Int: the current position of the margin |
dir |
Int: the base direction of the paragraph; if negative, the margin is to the right of the text, otherwise it is to the left. |
top |
Int: the top of the line |
baseline |
Int: the baseline of the line |
bottom |
Int: the bottom of the line |
text |
CharSequence: This value cannot be null . |
start |
Int: the start of the line |
end |
Int: the end of the line |
first |
Boolean: true if this is the first line of its paragraph |
layout |
Layout: This value cannot be null . |
getDrawable
open fun getDrawable(): Drawable
Returns the drawable used.
Return | |
---|---|
Drawable |
a drawable This value cannot be null . |
getLeadingMargin
open fun getLeadingMargin(first: Boolean): Int
Parameters | |
---|---|
first |
Boolean: true if the request is for the first line of a paragraph, false for subsequent lines |
Return | |
---|---|
Int |
the offset for the margin. |
getPadding
open fun getPadding(): Int
Returns a distance between the drawable and text in pixel.
The units of this value are pixels.
Return | |
---|---|
Int |
a distance pixel from the text The units of this value are pixels. {} |
toString
open fun toString(): String
Return | |
---|---|
String |
a string representation of the object. |