package com.tejia.lijin.app.util;
|
|
import android.content.Context;
|
import android.graphics.Bitmap;
|
import android.graphics.Canvas;
|
import android.graphics.Paint;
|
import android.graphics.drawable.Drawable;
|
import androidx.annotation.NonNull;
|
import android.text.style.ImageSpan;
|
|
/**
|
* Created by weikou2015 on 2017/3/6.
|
*/
|
|
public class VerticalImageSpan extends ImageSpan {
|
|
private Context mContext;
|
private Boolean isShare = false;
|
|
public VerticalImageSpan(Context context, final int des) {
|
super(context, des);
|
this.mContext = context;
|
}
|
|
|
public VerticalImageSpan(Context context, Bitmap des) {
|
super(context, des);
|
this.mContext = context;
|
}
|
|
public VerticalImageSpan(Drawable drawable) {
|
super(drawable);
|
}
|
|
@Override
|
public void draw(@NonNull Canvas canvas, CharSequence text,
|
int start, int end, float x,
|
int top, int y, int bottom, @NonNull Paint paint) {
|
// image to draw
|
Drawable b = getDrawable();
|
// font metrics of text to be replaced
|
Paint.FontMetricsInt fm = paint.getFontMetricsInt();
|
int transY = (y + fm.descent + y + fm.ascent) / 2
|
- b.getBounds().bottom / 2;
|
|
canvas.save();
|
canvas.translate(x, transY);
|
b.draw(canvas);
|
canvas.restore();
|
}
|
}
|