Added in API level 1

ImageSpan


open class ImageSpan : DynamicDrawableSpan

Span that replaces the text it's attached to with a Drawable that can be aligned with the bottom or with the baseline of the surrounding text. The drawable can be constructed from varied sources:

The default value for the vertical alignment is DynamicDrawableSpan.ALIGN_BOTTOM

For example, an ImagedSpan can be used like this:

SpannableString string = new SpannableString("Bottom: span.\nBaseline: span.");
  // using the default alignment: ALIGN_BOTTOM
  string.setSpan(new ImageSpan(this, R.mipmap.ic_launcher), 7, 8, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
  string.setSpan(new ImageSpan(this, R.mipmap.ic_launcher, DynamicDrawableSpan.ALIGN_BASELINE),
  22, 23, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
  
Text with ImageSpans aligned bottom and baseline.

Summary

Inherited constants
Int ALIGN_BASELINE

A constant indicating that the bottom of this span should be aligned with the baseline of the surrounding text.

Int ALIGN_BOTTOM

A constant indicating that the bottom of this span should be aligned with the bottom of the surrounding text, i.e., at the same level as the lowest descender in the text.

Int ALIGN_CENTER

A constant indicating that this span should be vertically centered between the top and the lowest descender.

Public constructors
ImageSpan(context: Context, bitmap: Bitmap)

Constructs an ImageSpan from a Context and a Bitmap with the default alignment DynamicDrawableSpan.ALIGN_BOTTOM

ImageSpan(context: Context, bitmap: Bitmap, verticalAlignment: Int)

Constructs an ImageSpan from a Context, a Bitmap and a vertical alignment.

ImageSpan(context: Context, uri: Uri)

Constructs an ImageSpan from a Context and a Uri with the default alignment DynamicDrawableSpan.ALIGN_BOTTOM.

ImageSpan(context: Context, uri: Uri, verticalAlignment: Int)

Constructs an ImageSpan from a Context, a Uri and a vertical alignment.

ImageSpan(context: Context, resourceId: Int)

Constructs an ImageSpan from a Context and a resource id with the default alignment DynamicDrawableSpan.ALIGN_BOTTOM

ImageSpan(context: Context, resourceId: Int, verticalAlignment: Int)

Constructs an ImageSpan from a Context, a resource id and a vertical alignment.

ImageSpan(b: Bitmap, verticalAlignment: Int)

ImageSpan(drawable: Drawable)

Constructs an ImageSpan from a drawable with the default alignment DynamicDrawableSpan.ALIGN_BOTTOM.

ImageSpan(drawable: Drawable, verticalAlignment: Int)

Constructs an ImageSpan from a drawable and a vertical alignment.

ImageSpan(drawable: Drawable, source: String)

Constructs an ImageSpan from a drawable and a source with the default alignment DynamicDrawableSpan.ALIGN_BOTTOM

ImageSpan(drawable: Drawable, source: String, verticalAlignment: Int)

Constructs an ImageSpan from a drawable, a source and a vertical alignment.

Public methods
open Drawable!

open String?

Returns the source string that was saved during construction.

open String

Inherited functions
Unit draw(canvas: Canvas, text: CharSequence!, start: Int, end: Int, x: Float, top: Int, y: Int, bottom: Int, paint: Paint)

Draws the span into the canvas.

Int getSize(paint: Paint, text: CharSequence!, start: Int, end: Int, fm: Paint.FontMetricsInt?)

Returns the width of the span. Extending classes can set the height of the span by updating attributes of android.graphics.Paint.FontMetricsInt. If the span covers the whole text, and the height is not set, draw(android.graphics.Canvas,java.lang.CharSequence,int,int,float,int,int,int,android.graphics.Paint) will not be called for the span.

Int getVerticalAlignment()

Returns the vertical alignment of this span, one of ALIGN_BOTTOM, ALIGN_BASELINE or ALIGN_CENTER.

CharSequence? getContentDescription()

Gets a brief description of this ReplacementSpan for use in accessibility support.

Unit setContentDescription(contentDescription: CharSequence?)

Sets the specific content description into ReplacementSpan. ReplacementSpans are shared with accessibility services, but only the content description is available from them.

Unit updateDrawState(ds: TextPaint!)

This method does nothing, since ReplacementSpans are drawn explicitly instead of affecting Paint properties.

Unit updateMeasureState(p: TextPaint)

This method does nothing, since ReplacementSpans are measured explicitly instead of affecting Paint properties.

MetricAffectingSpan! getUnderlying()

Returns "this" for most MetricAffectingSpans, but for MetricAffectingSpans that were generated by wrap, returns the underlying MetricAffectingSpan.

Unit updateDrawState(tp: TextPaint!)

CharacterStyle! wrap(cs: CharacterStyle!)

A given CharacterStyle can only applied to a single region of a given Spanned. If you need to attach the same CharacterStyle to multiple regions, you can use this method to wrap it with a new object that will have the same effect but be a distinct object so that it can also be attached without conflict.

Inherited properties

Public constructors

ImageSpan

Added in API level 4
ImageSpan(
    context: Context,
    bitmap: Bitmap)

Constructs an ImageSpan from a Context and a Bitmap with the default alignment DynamicDrawableSpan.ALIGN_BOTTOM

Parameters
context Context: context used to create a drawable from {@param bitmap} based on the display metrics of the resources This value cannot be null.
bitmap Bitmap: bitmap to be rendered This value cannot be null.

ImageSpan

Added in API level 4
ImageSpan(
    context: Context,
    bitmap: Bitmap,
    verticalAlignment: Int)

Constructs an ImageSpan from a Context, a Bitmap and a vertical alignment.

Parameters
context Context: context used to create a drawable from {@param bitmap} based on the display metrics of the resources This value cannot be null.
bitmap Bitmap: bitmap to be rendered This value cannot be null.
verticalAlignment Int: one of DynamicDrawableSpan.ALIGN_BOTTOM or DynamicDrawableSpan.ALIGN_BASELINE

ImageSpan

Added in API level 1
ImageSpan(
    context: Context,
    uri: Uri)

Constructs an ImageSpan from a Context and a Uri with the default alignment DynamicDrawableSpan.ALIGN_BOTTOM. The Uri source can be retrieved via getSource()

Parameters
context Context: context used to create a drawable from {@param bitmap} based on the display metrics of the resources This value cannot be null.
uri Uri: Uri used to construct the drawable that will be rendered This value cannot be null.

ImageSpan

Added in API level 3
ImageSpan(
    context: Context,
    uri: Uri,
    verticalAlignment: Int)

Constructs an ImageSpan from a Context, a Uri and a vertical alignment. The Uri source can be retrieved via getSource()

Parameters
context Context: context used to create a drawable from {@param bitmap} based on the display metrics of the resources This value cannot be null.
uri Uri: Uri used to construct the drawable that will be rendered. This value cannot be null.
verticalAlignment Int: one of DynamicDrawableSpan.ALIGN_BOTTOM or DynamicDrawableSpan.ALIGN_BASELINE

ImageSpan

Added in API level 1
ImageSpan(
    context: Context,
    resourceId: Int)

Constructs an ImageSpan from a Context and a resource id with the default alignment DynamicDrawableSpan.ALIGN_BOTTOM

Parameters
context Context: context used to retrieve the drawable from resources This value cannot be null.
resourceId Int: drawable resource id based on which the drawable is retrieved

ImageSpan

Added in API level 3
ImageSpan(
    context: Context,
    resourceId: Int,
    verticalAlignment: Int)

Constructs an ImageSpan from a Context, a resource id and a vertical alignment.

Parameters
context Context: context used to retrieve the drawable from resources This value cannot be null.
resourceId Int: drawable resource id based on which the drawable is retrieved.
verticalAlignment Int: one of DynamicDrawableSpan.ALIGN_BOTTOM or DynamicDrawableSpan.ALIGN_BASELINE

ImageSpan

Added in API level 1
ImageSpan(b: Bitmap)

Deprecated: Use ImageSpan(android.content.Context,android.graphics.Bitmap) instead.

Parameters
b Bitmap: This value cannot be null.

ImageSpan

Added in API level 3
ImageSpan(
    b: Bitmap,
    verticalAlignment: Int)

Deprecated: Use ImageSpan(android.content.Context,android.graphics.Bitmap,int) instead.

Parameters
b Bitmap: This value cannot be null.

ImageSpan

Added in API level 1
ImageSpan(drawable: Drawable)

Constructs an ImageSpan from a drawable with the default alignment DynamicDrawableSpan.ALIGN_BOTTOM.

Parameters
drawable Drawable: drawable to be rendered This value cannot be null.

ImageSpan

Added in API level 3
ImageSpan(
    drawable: Drawable,
    verticalAlignment: Int)

Constructs an ImageSpan from a drawable and a vertical alignment.

Parameters
drawable Drawable: drawable to be rendered This value cannot be null.
verticalAlignment Int: one of DynamicDrawableSpan.ALIGN_BOTTOM or DynamicDrawableSpan.ALIGN_BASELINE

ImageSpan

Added in API level 1
ImageSpan(
    drawable: Drawable,
    source: String)

Constructs an ImageSpan from a drawable and a source with the default alignment DynamicDrawableSpan.ALIGN_BOTTOM

Parameters
drawable Drawable: drawable to be rendered This value cannot be null.
source String: drawable's Uri source This value cannot be null.

ImageSpan

Added in API level 3
ImageSpan(
    drawable: Drawable,
    source: String,
    verticalAlignment: Int)

Constructs an ImageSpan from a drawable, a source and a vertical alignment.

Parameters
drawable Drawable: drawable to be rendered This value cannot be null.
source String: drawable's uri source This value cannot be null.
verticalAlignment Int: one of DynamicDrawableSpan.ALIGN_BOTTOM or DynamicDrawableSpan.ALIGN_BASELINE

Public methods

getDrawable

Added in API level 1
open fun getDrawable(): Drawable!

getSource

Added in API level 1
open fun getSource(): String?

Returns the source string that was saved during construction.

Return
String? the source string that was saved during construction This value may be null.

toString

Added in API level 1
open fun toString(): String
Return
String a string representation of the object.