我创建了一个倒数计时器,它使用自定义textView和自定义字体 计时器本身工作正常,但应用程序的所有其他部分都有点滞后(这对于默认字体来说不是问题)。
public class MyTextView extends TextView {
private static Typeface myTypeface;
private static float strokeWidth;
public MyTextView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
init();
}
public MyTextView(Context context, AttributeSet attrs) {
super(context, attrs);
init();
}
public MyTextView(Context context) {
super(context);
init();
}
private void init() {
if (myTypeface == null) {
myTypeface = Typeface.createFromAsset(getContext().getAssets(), "fonts/blow.ttf");
strokeWidth = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 2, getResources().getDisplayMetrics());
}
setTypeface(myTypeface);
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
Paint paint = getPaint();
int color = paint.getColor();
paint.setStyle(Paint.Style.STROKE);
setTextColor(Color.BLACK);
paint.setStrokeWidth(strokeWidth);
super.onDraw(canvas);
setTextColor(color);
paint.setStyle(Paint.Style.FILL);
}
}