Custom View not drawn properly

Question

I have a custom indicator view that I have created.

enter image description here

as you can see on the first picture everything is drawn correctly, but sometimes when i close the app and start it again it is not drawn correctly (the second picture)

trying to figure out what could be the reason for this. maybe some caching ?

this is my onDraw Code:

@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);
        }
    }
}

Show source
| android   | view   2017-01-03 09:01 0 Answers

Answers to Custom View not drawn properly ( 0 )

Leave a reply to - Custom View not drawn properly

◀ Go back