Android, draw clock off-center

I am trying to achieve this WatchFace using Android API:

ScreenShot of desired watch face

These are my paints used for hours, minutes and seconds:

secondsPaint.setAntiAlias(true);
secondsPaint.setColor(Color.RED);
secondsPaint.setStyle(Paint.Style.STROKE);
secondsPaint.setStrokeJoin(Paint.Join.ROUND);
secondsPaint.setStrokeWidth(3f);
secondsPaint.setAntiAlias(true);
minutesPaint.setColor(Color.WHITE);
minutesPaint.setStyle(Paint.Style.STROKE);
minutesPaint.setStrokeJoin(Paint.Join.ROUND);
minutesPaint.setStrokeWidth(4f);
hoursPaint.setAntiAlias(true);
hoursPaint.setColor(Color.WHITE);
hoursPaint.setStyle(Paint.Style.STROKE);
hoursPaint.setStrokeJoin(Paint.Join.ROUND);
hoursPaint.setStrokeWidth(5f);

      

I have applied the following code to draw the background, seconds, minutes and hours:

// Background
canvas.drawBitmap(background, 0, 0, null);

      

Then I draw hours and minutes

// Draw the minute and hour hands.
float minX = (float) Math.sin(minRot) * minLength;
float minY = (float) -Math.cos(minRot) * minLength;
canvas.drawLine(centerX, centerY, centerX + minX, centerY + minY, minutesPai
float hrX = (float) Math.sin(hrRot) * hrLength;
float hrY = (float) -Math.cos(hrRot) * hrLength;
canvas.drawLine(centerX, centerY, centerX + hrX, centerY + hrY, hoursPaint);

      

And finally seconds

// draw seconds
float secX = (float) Math.sin(secRot) * secLength;
float secY = (float) -Math.cos(secRot) * secLength;
canvas.drawLine(centerX, centerY, centerX + secX, centerY + secY, secondsPaint);

      

I need:

  • create a circle in the middle of the screen and move the hours, minutes and seconds with a few pixels from the center as the image is displayed.
  • Make seconds and minutes "smoother" anti-aliasing is set, but it does not work as expected

At the moment, the result is as follows:

Actual WatchFace

+3


source to share


1 answer


Drawing a circle is as easy as using drawCircle()

.
So the dirty trick might be to paint white and another larger (and maybe even smaller) of the same background color to cover some of the minutes and seconds hands.

So, getting after the hand, these circles will cover the part you want to hide.

A very cheap trick (no other trigonometry).
Works exactly.



You can even use a list-fit layer in the center ...;)

But drawCircle () is pretty simple I guess.

+2


source







All Articles