徽章系统入口及MTA数据统计
This commit is contained in:
53
app/src/main/java/com/gh/common/view/CenterImageSpan.java
Normal file
53
app/src/main/java/com/gh/common/view/CenterImageSpan.java
Normal file
@ -0,0 +1,53 @@
|
||||
package com.gh.common.view;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Paint;
|
||||
import android.graphics.Rect;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.text.style.ImageSpan;
|
||||
|
||||
/**
|
||||
* 图文中心对齐
|
||||
*/
|
||||
public class CenterImageSpan extends ImageSpan {
|
||||
public CenterImageSpan(Context context, int resourceId) {
|
||||
super(context, resourceId);
|
||||
}
|
||||
public CenterImageSpan(Drawable drawable) {
|
||||
super( drawable);
|
||||
}
|
||||
|
||||
public int getSize(Paint paint, CharSequence text, int start, int end,
|
||||
Paint.FontMetricsInt fm) {
|
||||
Drawable d = getDrawable();
|
||||
Rect rect = d.getBounds();
|
||||
if (fm != 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;
|
||||
|
||||
fm.ascent = -bottom;
|
||||
fm.top = -bottom;
|
||||
fm.bottom = top;
|
||||
fm.descent = top;
|
||||
}
|
||||
return rect.right;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(Canvas canvas, CharSequence text, int start, int end,
|
||||
float x, int top, int y, int bottom, Paint paint) {
|
||||
Drawable b = getDrawable();
|
||||
canvas.save();
|
||||
int transY = 0;
|
||||
transY = ((bottom - top) - b.getBounds().bottom) / 2 + top;
|
||||
canvas.translate(x, transY);
|
||||
b.draw(canvas);
|
||||
canvas.restore();
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user