emojicon
emojicon copied to clipboard
why the image looook seems lower than the text ?
emojicon:emojiconSize +4sp >= android:textSize will have a better performace...
it seems ..the view don't handle
android:lineSpacingExtra="10sp"
android:lineSpacingMultiplier="1.1"
so .the emoji will lower than the char.
Hey @Sanjay-F Am getting Cannot Resolve method error in setUseSystemDefault and newInstance. Any idea where I am going wrong?
@Sanjay-F 你处理好这个问题了吗?
Fixed in 2b58b54. Please try out 1.2-SNAPSHOT
.
@rockerhieu Still no handle android:lineSpacingExtra="10sp"
@KennethYo try it if (mVerticalAlignment == ALIGN_BASELINE) { transY = top + ((paint.getFontMetricsInt().descent - paint.getFontMetricsInt().ascent) / 2) - ((b.getBounds().bottom - b.getBounds().top) / 2) - mTop; }
@Sanjay-F I guess this emoji's layout problem comes from the "MultiplelineSpace" property. When this property is set, both the bottom line and base line of the text have changed. Thus, no matter the alignment is the ALIGN_BASELINE or not, it would be lower a little bit.
I believe the only method to fix this problem is using customized ImageSpan. Here is the answer
Wish it could help :smile:
anyone got any working solution.. please share
public class EmojiconSpan extends DynamicDrawableSpan {
private final Context mContext;
private final int mResourceId;
private Drawable mDrawable;
private WeakReference<Drawable> mDrawableRef;
public EmojiconSpan(Context context, int resourceId, int emojiSize, int alignment, int textSize) {
super(alignment);
mContext = context;
mResourceId = resourceId;
}
public Drawable getDrawable() {
if (mDrawable == null) {
try {
mDrawable = mContext.getResources().getDrawable(mResourceId);
if (mVerticalAlignment == ALIGN_BASELINE) {
mDrawable.setBounds(0, 0, mDrawable.getIntrinsicHeight() + 20, mDrawable.getIntrinsicWidth() + 20);
}
} catch (Exception e) {
e.printStackTrace();
}
}
return mDrawable;
}
@Override
public void draw(Canvas canvas, CharSequence text, int start, int end, float x, int top, int y, int bottom, Paint paint) {
Drawable b = getCachedDrawable();
canvas.save();
int transY = bottom - b.getBounds().bottom;
if (mVerticalAlignment == ALIGN_BASELINE) {
Paint.FontMetricsInt fmPaint = paint.getFontMetricsInt();
int fontHeight = fmPaint.descent - fmPaint.ascent;
int centerY = y + fmPaint.descent - fontHeight / 2;
transY = centerY - (mDrawable.getBounds().bottom - mDrawable.getBounds().top) / 2;
}
canvas.translate(x, transY);
b.draw(canvas);
canvas.restore();
}
public int getSize(Paint paint, CharSequence text, int start, int end, Paint.FontMetricsInt fontMetricsInt) {
Drawable drawable = this.getDrawable();
Rect rect = drawable.getBounds();
if (fontMetricsInt != null) {
Paint.FontMetricsInt fmPaint = paint.getFontMetricsInt();
int fontHeight = fmPaint.bottom - fmPaint.top;
int drHeight = rect.bottom - rect.top;
int top = drHeight / 2 - fontHeight / 4;
int bottom = drHeight / 2 + fontHeight / 4;
fontMetricsInt.ascent = -bottom;
fontMetricsInt.top = -bottom;
fontMetricsInt.bottom = top;
fontMetricsInt.descent = top;
}
return rect.right;
}
private Drawable getCachedDrawable() {
if (mDrawableRef == null || mDrawableRef.get() == null) {
mDrawableRef = new WeakReference<Drawable>(getDrawable());
}
return mDrawableRef.get();
}
}
@zjc can you send a PR for this?
sorry for my pool english ,i modify the EmojiconSpan.java, you can add a emojiconAlignment wrap_drawable for Solve this problem