-1

I would like to get size of the Android Phone but size in mm and not in pixels.

I know how to get size in pixels, however I would like to do some RND and for that I want to get width of the screen in mm.

Like here Galaxy S4 size is Dimensions 136.6 x 69.8 x 7.9 mm (5.38 x 2.75 x 0.31 in)

136.6 x 69.8 x 7.9 mm (5.38 x 2.75 x 0.31 in)
               ^^^
               Does any one knows what is this size for?

Though I am iPhone developer BUT I am beginner (1 day baby) for Android. Well below is what I want to do as RND.

Let's say designer gives me design for the app of size 1080*1920 and have title of size 30px (which covers 80% exactly) of the screen size.

That means 10% space on left side, 80% text and 10% space on right side.

I know in Android we have something called sp or android:textAppearance="@android:style/TextAppearance.Large", but that won't give the 10% spaces.

What I want to achieve is regardless of size, design should go same.

Considering design to fit with width, if height increases, I would have scrollview and I am okay with that.

Michael Dodd
  • 10,102
  • 12
  • 51
  • 64
Fahim Parkar
  • 30,974
  • 45
  • 160
  • 276
  • 1
    possible duplicate of [Is there a way to determine android physical screen height in cm or inches?](http://stackoverflow.com/questions/2193457/is-there-a-way-to-determine-android-physical-screen-height-in-cm-or-inches) – mittelmania Dec 23 '14 at 13:56
  • @Krupal the OP explicitly asked on line 1 for **size in mm and not in pixels** – shkschneider Dec 23 '14 at 13:58
  • 1
    `Does any one knows what is this size for?` It's the device **depth**. `136.6 x 69.8 x 7.9 mm (5.38 x 2.75 x 0.31 in)` is `height x width x depth` – Phantômaxx Dec 23 '14 at 14:01
  • You could in theory use the display density and the pixel size to convert to a physical size, however in reality this never works because the density is not precisely accurate – Greg Ennis Dec 23 '14 at 14:03

2 Answers2

0

Use DisplayMetrics. The API is: http://developer.android.com/reference/android/util/DisplayMetrics.html You can perform a calculation on the given fields and obtain the height and width in inches, then convert that to mm.

AliAvci
  • 1,127
  • 10
  • 20
0

"Pixel density" is the number of pixels per inch. So dpi gives you the scale factor you need so that the number of pixels is consistent across devices.

Another way of saying this is that if you have a 480 pixel screen with hdpi, then a 360 pixel screen at mdpi is about the same physical size. While the screen sizes may vary some, it generally is not that important. Even so, as mentioned, see this post about doing the actual calculation:

Is there a way to determine android physical screen height in cm or inches?

However, you are talking about percentages of screen size in your example. If you know the screen size in pixels, then the physical size doesn't matter, just do your calculations using pixels. If you have 480 pixels, 10% is 48.

You cannot do this in XML, which it sounds like you might be wanting to do. You can use "weighted linear layouts" for runtime calculations of the screen size. You can also use different res folders depending on screen size (like res/layout-hdpi).

You may want to read this from Google regarding supporting different screen sizes: http://developer.android.com/guide/practices/screens_support.html

Community
  • 1
  • 1
Jim
  • 10,172
  • 1
  • 27
  • 36