Drawing shapes of different sizes depending on the resolution

I am trying to write an android application.
Therefore, I have a SurfaceView class that draws all objects.

Now, when, for example, I draw a circle, I must specify the size.
Is there a way to make this size depending on how large the screen resolution and density are?
Since when drawing a circle, I want it to be the same size on a lower resolution device as on a high resolution device.

When drawing a circle with a radius of 50px, it will be larger on smaller screens than on large screens.

Any ideas?

EDIT: I know that when creating some layout I could use density pixels. But I do not work on layouts, I draw on top of the surface. when drawing something like

canvas.drawCircle(x, y, size, paint);

size declares a radius in a pixel. Is there a way to convert pixels to density pixels? Any method or simliar?

Thanks in advance

+3
source share
1 answer

I think the formula you are looking for (dip → px) is published here:

What is the correct way to specify sizes in DIP from Java code?

+4
source

All Articles