DynamicDrawableSpan.javaAPI DocAndroid 5.1 API3570Thu Mar 12 22:22:10 GMT


public abstract class DynamicDrawableSpan extends ReplacementSpan

Fields Summary
private static final String
public static final int
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.
public static final int
A constant indicating that the bottom of this span should be aligned with the baseline of the surrounding text.
protected final int
private WeakReference
Constructors Summary
public DynamicDrawableSpan()

        mVerticalAlignment = ALIGN_BOTTOM;
protected DynamicDrawableSpan(int verticalAlignment)

verticalAlignment one of {@link #ALIGN_BOTTOM} or {@link #ALIGN_BASELINE}.

        mVerticalAlignment = verticalAlignment;
Methods Summary
public voiddraw( canvas, java.lang.CharSequence text, int start, int end, float x, int top, int y, int bottom, paint)

        Drawable b = getCachedDrawable();;
        int transY = bottom - b.getBounds().bottom;
        if (mVerticalAlignment == ALIGN_BASELINE) {
            transY -= paint.getFontMetricsInt().descent;

        canvas.translate(x, transY);

        WeakReference<Drawable> wr = mDrawableRef;
        Drawable d = null;

        if (wr != null)
            d = wr.get();

        if (d == null) {
            d = getDrawable();
            mDrawableRef = new WeakReference<Drawable>(d);

        return d;
public abstract
Your subclass must implement this method to provide the bitmap to be drawn. The dimensions of the bitmap must be the same from each call to the next.

public intgetSize( paint, java.lang.CharSequence text, int start, int end, Paint.FontMetricsInt fm)

        Drawable d = getCachedDrawable();
        Rect rect = d.getBounds();

        if (fm != null) {
            fm.ascent = -rect.bottom; 
            fm.descent = 0; 

   = fm.ascent;
            fm.bottom = 0;

        return rect.right;
public intgetVerticalAlignment()
Returns the vertical alignment of this span, one of {@link #ALIGN_BOTTOM} or {@link #ALIGN_BASELINE}.

        return mVerticalAlignment;