@Override protected void onDraw(Canvas canvas) { int width = getWidth() - getPaddingLeft() - getPaddingRight(); int height = getHeight() - getPaddingTop() - getPaddingBottom(); if (backgroundDrawable != null) { int dw = backgroundDrawable.getIntrinsicWidth(); int left = getPaddingLeft() + (width - dw) / 2; int top = getPaddingTop(); int right = left + dw; int bottom = height + getPaddingTop(); backgroundDrawable.setBounds(left, top, right, bottom); backgroundDrawable.draw(canvas); } if (progressDrawable != null) { int dw = progressDrawable.getIntrinsicWidth(); int left = getPaddingLeft() + (width - dw) / 2; int top = getPaddingTop(); int right = left + dw; int bottom = height + getPaddingTop(); progressDrawable.setBounds(left, top, right, bottom); progressDrawable.setLevel((int) (10000 * progress.percentage())); progressDrawable.draw(canvas); } int textWidth = (int) paint.measureText(progress.toString()); int x = (width - textWidth) / 2 + getPaddingLeft(); int y = height / 2 + getPaddingTop() - (int) (paint.getTextSize() / 2); canvas.drawText(progress.toString(), x, y, paint); }