我需要创建进度条,所以我通过扩展 ProgressBar 在 onDraw 方法中完成了它,并且此代码在所有 android 设备中工作,除了 Galaxy nexus .. 虽然它没有抛出和异常,但进度可绘制并没有通过 asynctask 更新。此代码完全适用于除银河系外的所有设备
@Override
protected synchronized void onDraw(Canvas canvas) {
super.onDraw(canvas);
Paint textPaint = new Paint();
textPaint.setAntiAlias(true);
textPaint.setColor(textColor);
Typeface tmTypeface = Typeface.create(Typeface.SANS_SERIF, Typeface.BOLD);
textPaint.setTypeface(tmTypeface);
textPaint.setTextSize(textSize * mContext.getResources().getDisplayMetrics().density);
Rect bounds = new Rect();
textPaint.getTextBounds(text, 0, text.length(), bounds);
int x = getWidth() / 2 - bounds.centerX();
int y = getHeight() / 2 - bounds.centerY();
canvas.drawBitmap(thumbnailBitmap, 10, y - bitmapHeight / 2, null);
canvas.drawText(text, 15 + thumbnailBitmap.getWidth(), y, textPaint);
canvas.drawBitmap(downloadBitmap, getWidth() - bitmapWidth, y - bitmapHeight / 2, null);
}
问题可能与可绘制和样式有关,但它适用于所有版本和所有设备