DynamicDrawableSpanpublic abstract class DynamicDrawableSpan extends ReplacementSpan
Fields Summary |
---|
private static final String | TAG | public static final int | ALIGN_BOTTOMA 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 | ALIGN_BASELINEA constant indicating that the bottom of this span should be aligned
with the baseline of the surrounding text. | protected final int | mVerticalAlignment | private WeakReference | mDrawableRef |
Constructors Summary |
---|
public DynamicDrawableSpan()
mVerticalAlignment = ALIGN_BOTTOM;
| protected DynamicDrawableSpan(int verticalAlignment)
mVerticalAlignment = verticalAlignment;
|
Methods Summary |
---|
public void | draw(android.graphics.Canvas canvas, java.lang.CharSequence text, int start, int end, float x, int top, int y, int bottom, android.graphics.Paint paint)
Drawable b = getCachedDrawable();
canvas.save();
int transY = bottom - b.getBounds().bottom;
if (mVerticalAlignment == ALIGN_BASELINE) {
transY -= paint.getFontMetricsInt().descent;
}
canvas.translate(x, transY);
b.draw(canvas);
canvas.restore();
| private android.graphics.drawable.Drawable | getCachedDrawable()
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 android.graphics.drawable.Drawable | getDrawable()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 int | getSize(android.graphics.Paint 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.top = fm.ascent;
fm.bottom = 0;
}
return rect.right;
| public int | getVerticalAlignment()Returns the vertical alignment of this span, one of {@link #ALIGN_BOTTOM} or
{@link #ALIGN_BASELINE}.
return mVerticalAlignment;
|
|