Made a CustomView for drawing the ProgressBar and in the center of the text the percentage of completed:
public class MyView extends View { ... public void setRotation(int rotate){ mRotate = rotate; } public int getRotation(){ return mRotate; } public void initCircle(){ setFocusable(true); mPaint = new Paint(Paint.ANTI_ALIAS_FLAG); mTextPaint = new Paint(Paint.ANTI_ALIAS_FLAG); mPaint.setColor(Color.WHITE); mPaint.setStrokeWidth(50); mPaint.setStyle(Paint.Style.STROKE); mTextPaint.setColor(Color.WHITE); mTextPaint.setStyle(Paint.Style.STROKE); } @Override public void onDraw(Canvas canvas) { super.onDraw(canvas); int width = getMeasuredWidth(); int height = getMeasuredHeight(); int radius; if (width > height) { radius = height / 4; } else { radius = width / 4; } int center_x, center_y; center_x = width / 2; center_y = height / 4; final RectF oval = new RectF(); oval.set(center_x - radius, center_y - radius, center_x + radius, center_y + radius); center_x = width / 2; center_y = height * 3 / 4; oval.set(center_x - radius, center_y - radius, center_x + radius, center_y + radius); text = String.valueOf(Math.round(360 / (mRotate * 100))); canvas.drawText(text + "%", center_x, center_y, mTextPaint); canvas.drawArc(oval, -90, mRotate, false, mPaint); } } I have a getter and a setter for updating the state of rotation for drawing.
In Activity, through Thread update the rotation myView.setRotation(count) .
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); myView = (MyView)findViewById(R.id.myview); myView.setRotation(1); Thread thread = new Thread(null, new Runnable() { @Override public void run() { while (myView.getRotation() < 360) { count += 2; try { Thread.sleep(300); } catch (InterruptedException e) { e.printStackTrace(); } mHandler.post(new Runnable() { @Override public void run() { myView.setRotation(count); } }); } } }); thread.start(); } As a result, the update of the drawing on the device does not occur, on the emulator it is drawn, but with jerks and only with a quick tap on the screen.
Do I have an error in creating a thread or a joint with draw() ?