I have a major issue I am working on for days now. It is much understandable by looking at the requirement first. I will list down my requirement as simple as possible in point form below.
- I have 5 android phones. 5 different brands, different screen sizes.
- Imagine the screen sizes are 4inch, 4.5inch, 5inch, 5.1inch and 5.2inch
- I have an android app and it has a drawing canvas.
- Now using
canvas.drawCircle(x / 2, y / 2, radius, paint)
I am drawing a circle. Imagine the radius is 100 (100 pixels?) - I install this app in my smallest screen phone, 4inch. Then I use a ruler and measure the the circle diameter. Imagine the circle diameter is "exact" 3cm.
- Now I install this in my other phones.
- Unfortunately, in my 4.5 inch phone the circle diameter is 3.2cm. In 5 inch phone it is 3.3 cm. In 5.1 inch phone it is 2.8cm and so on.
- However I want my circle diameter to be 3cm (exact 3cm) in every phone.
Above requirement is something I am trying for days now. I tried the following to make sure I get a circle with no size change across all screens.
- Using
ImageView
- I tried using anImageView
and added a circle image. I have given the width, height fixed. I have tryied setting the values inpx
,dp
,inches
etc. I also triedscalling
options available forImageView
. Also tried placing the same image indrawable-nodpi
folder. Tried creating drawable folders for all sizes (ex: drawable-mdpi, drawable-hdpi). Non of this stopped the image from being scaled. - Using Canvas - As explained in the above, I tried using canvas and drawing the image. The drawing scales.
- Finding pixels per inch.- Tried finding pixels per inch of each phone programatically thinking I can find a way to develop a logic from it to dynamically draw the images in same size. I used several links including - Calculate PPI of Android Device. Most of them talk about getting screen resolution only.
How can I fulfill my requirement of drawing same size circles? If it can be done by knowing PPI, how should I do it?