我有一个我创建的自定义指标视图。
正如你在第一张照片上看到的,一切都被正确绘制, 但有时当我关闭应用程序并再次启动它时,它绘制得不正确(第二张图片)
试图找出可能是什么原因。 也许是一些缓存?
这是我的onDraw
代码:
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
drawUnselected(canvas, mUnselectedPaint);
drawSelected(canvas, mSelectedPaint);
drawDone(canvas, mDonePaint);
}
private void drawDone(Canvas canvas, Paint mDonePaint) {
for (Integer page : mDonePages) {
canvas.drawBitmap(mDoneItemBitmap, dotCenterX[page], mDotTopY, mDonePaint);
}
}
private void drawSelected(Canvas canvas, Paint mSelectedPaint) {
float dist = ((mSelectedPaint.descent() + mSelectedPaint.ascent()) / 2);
for (Integer page : mSelectedPages) {
canvas.drawBitmap(mSelectedItemBitmap, dotCenterX[page], mDotTopY, mSelectedPaint);
canvas.drawText("" + (page + 1), dotCenterX[page] + mDotRadius + dist, mDotTopY + mDotRadius - dist, mSelectedPaint);
}
}
private void drawUnselected(Canvas canvas, Paint mUnselectedPaint) {
int paddingTop = getPaddingTop();
for (int page = 0; page < mDotsNumber; page++) {
Paint test = new Paint();
test.setColor(Color.BLACK);
test.setStrokeWidth(30);
canvas.drawBitmap(mUnSelectedItemBitmap, dotCenterX[page], mDotTopY, mUnselectedPaint);
float dist = ((mNumbersPaint.descent() + mNumbersPaint.ascent()) / 2);
canvas.drawText("" + (page + 1), dotCenterX[page] + mDotRadius + dist, mDotTopY + mDotRadius - dist, mNumbersPaint);
if (page == mDotsNumber - 1) {
//last page
} else {
canvas.drawLine(dotCenterX[page] + mDotDiameter - 2, mDotRadius + paddingTop, dotCenterX[page] + mDotDiameter + mDotGap + 1, mDotRadius + paddingTop, mUnselectedPaint);
}
}
}