3
votes

I am trying to write an app for android.
Therefore I've got a SurfaceView class drawing all objects.

Now, when for instance I'm drawing a circle, I have to specify a size.
Is there a way making this size depending on how big the screen resolution and density is?
Becausei 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 50px radius, it would be bigger on smaller screens than on bigger screens.

Any ideas?

EDIT: I know when creating some layout i could use density-pixels. But I am not working on layouts, i am drawing on top of a surfaceview. when drawing something like

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

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

Thanks in advance

1
You don't really want it to be the same size, but the same aspect. Because if the size is fixed (px), you then have density issues, as you noticed yourself.Phantômaxx
use density-pixel, not just pixelwaqaslam
the problem is when trying to draw for example a sphere, it asks me for precise coordinates and a radius. When i type canvas.drawCircle(); It has to be a float as radius. when declaring it to 5, it will have a radius of 5 pixels, not density pixels. how can i convert pixels to density pixels in code?user2410644
@fadden : going to check that, thanks!user2410644

1 Answers

4
votes

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

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