public class

BetterImageSpan

extends ReplacementSpan
java.lang.Object
   ↳ android.text.style.CharacterStyle
     ↳ android.text.style.MetricAffectingSpan
       ↳ android.text.style.ReplacementSpan
         ↳ com.facebook.widget.text.span.BetterImageSpan
Known Direct Subclasses

Class Overview

A better implementation of image spans that also supports centering images against the text.

In order to migrate from ImageSpan, replace new ImageSpan(drawable, alignment) with new BetterImageSpan(drawable, BetterImageSpan.normalizeAlignment(alignment)).

There are 2 main differences between BetterImageSpan and ImageSpan: 1. Pass in ALIGN_CENTER to center images against the text. 2. ALIGN_BOTTOM no longer unnecessarily increases the size of the text: DynamicDrawableSpan (ImageSpan's parent) adjusts sizes as if alignment was ALIGN_BASELINE which can lead to unnecessary whitespace.

Summary

Nested Classes
@interface BetterImageSpan.BetterImageSpanAlignment  
Constants
int ALIGN_BASELINE
int ALIGN_BOTTOM
int ALIGN_CENTER
Public Constructors
BetterImageSpan(Drawable drawable)
BetterImageSpan(Drawable drawable, int verticalAlignment)
Public Methods
void draw(Canvas canvas, CharSequence text, int start, int end, float x, int top, int y, int bottom, Paint paint)
Drawable getDrawable()
int getSize(Paint paint, CharSequence text, int start, int end, Paint.FontMetricsInt fontMetrics)
Returns the width of the image span and increases the height if font metrics are available.
final static int normalizeAlignment(int alignment)
A helper function to allow dropping in BetterImageSpan as a replacement to ImageSpan, and allowing for center alignment if passed in.
void updateBounds()
[Expand]
Inherited Methods
From class android.text.style.ReplacementSpan
From class android.text.style.MetricAffectingSpan
From class android.text.style.CharacterStyle
From class java.lang.Object

Constants

public static final int ALIGN_BASELINE

Constant Value: 1 (0x00000001)

public static final int ALIGN_BOTTOM

Constant Value: 0 (0x00000000)

public static final int ALIGN_CENTER

Constant Value: 2 (0x00000002)

Public Constructors

public BetterImageSpan (Drawable drawable)

public BetterImageSpan (Drawable drawable, int verticalAlignment)

Public Methods

public void draw (Canvas canvas, CharSequence text, int start, int end, float x, int top, int y, int bottom, Paint paint)

public Drawable getDrawable ()

public int getSize (Paint paint, CharSequence text, int start, int end, Paint.FontMetricsInt fontMetrics)

Returns the width of the image span and increases the height if font metrics are available.

public static final int normalizeAlignment (int alignment)

A helper function to allow dropping in BetterImageSpan as a replacement to ImageSpan, and allowing for center alignment if passed in.

public void updateBounds ()