Custom view not drawn properly

I have my own view of the indicator that I created.

enter image description here

as you can see in the first picture, everything is drawn correctly, but sometimes, when I close the application and start it again, it does not draw correctly (second image)

trying to figure out what could be causing this. perhaps 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); } } } 
+6
source share

Source: https://habr.com/ru/post/1013719/


All Articles