3

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

user2410644
  • 3,861
  • 6
  • 39
  • 59
  • 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 Feb 13 '14 at 15:46
  • use **density-pixel**, not just pixel – waqaslam Feb 13 '14 at 15:49
  • 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 Feb 13 '14 at 16:14
  • 1
    This might be of use: http://android-developers.blogspot.com/2013/09/using-hardware-scaler-for-performance.html – fadden Feb 14 '14 at 01:23
  • @fadden : going to check that, thanks! – user2410644 Feb 14 '14 at 15:11

1 Answers1

4

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?

Community
  • 1
  • 1
Nantoka
  • 4,174
  • 1
  • 33
  • 36