我需要創建進度條,所以我在onDraw方法中通過擴展ProgressBar來完成此代碼在所有Android設備上工作,除了galaxy nexus ..雖然它沒有引發異常但可繪製的進度不是通過asynctask來更新的。此代碼中的所有設備完全工作,除了Galaxy Nexus的自定義進度條不能在Galaxy Nexus設備上工作
@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);
}
的問題可能是繪製和風格,但它工作在所有版本和所有設備