emojicon icon indicating copy to clipboard operation
emojicon copied to clipboard

同时输入文字和表情的时候,发现文字和表情没有一起居中!

Open lfh1991 opened this issue 6 years ago • 1 comments

如题,同时输入文字和表情,文字会在底部,然后表情居中了,应该要文字和表情一起居中吧

lfh1991 avatar May 22 '18 03:05 lfh1991

重写getSize方法:

@Override public int getSize(Paint paint, CharSequence text, int start, int end, Paint.FontMetricsInt fontMetricsInt) { Drawable drawable = 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;
    }

github583431183 avatar Jul 23 '19 08:07 github583431183