我想在自定义视图中为文本提供弹出和返回效果。我正在尝试通过 Thread 更新 Cutome 视图中的文本大小,这会更新文本大小和PostInvalidate();
. 但它在客户视图中没有显示任何效果。
客户视图 OnDraw 方法:
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
canvas.drawText(carMessage, getPercentOfWidth(40),getPercentOfHeight(20),fontPaint);
canvas.drawBitmap(carSpriteImage, carspritePosition.x , carspritePosition.y, null);
}
字体更新线程类代码:
@Override
public void run() {
super.run();
while(true){
paint.setTextSize(minSize);
Log.i("Font Thread!", "Min Font Size="+minSize);
customeView.setCarMessage("Click Me");
customeView.setFontPaint(paint);
customeView.postInvalidate();
try {
Thread.sleep(700);
} catch (InterruptedException e) {
e.printStackTrace();
}
paint.setTextSize(maxSize);
customeView.setCarMessage("To Stop");
customeView.setFontPaint(paint);
Log.i("Font Thread!", "Max Font Size="+maxSize);
customeView.postInvalidate();
}
}