1

As you know if you put dimensions and size in dp it will almost same in all devices. I say almost because of bucket range. for example in hdpi that presnets with 240dpi a device with 200dpi and 279dpi all use hdpi resource and dimens folder and same size in pixel:

px = dp * (dpi/160)

enter image description here

so for example an object with 300dp size will be (dp/dpi=inch) 300/200 = 1.5 inch in first device (200dpi) and in another device it will be 300/279=1.07 inch. (279dpi device) so as you see there is too much difference between high and end of range hdpi and your UI not just same in inch.

Ok I found best solution for solving this problem is divide bucket to more specific with sw and change dp size in dimens.xml for each bucket range. but I do not know how to divide bucket and second how to create values for them!

problem is what is the proper folder range for this? what is the best practice for divide sw sizes for achieving this. (sw160, sw320, sw480 or what?) and how to add value for dimensions?

UPDATE

some friends say that why you won't use in instead of dp and this is my answer:

  1. Android get inch with the same formula (screen Resolution / dpi = inch) so the problem is same and it's is not exact in all devices.
  2. Android told that using inch and mm and cm is not recomended.
Mahdi
  • 6,139
  • 9
  • 57
  • 109
  • 1
    so dont use `dp` (`300dp`), use either: `pt` or `mm` or `in` – pskink Aug 28 '16 at 06:01
  • I'm a bit confused. What's the relevance of the sw folders? You can have sw480 devices with a huge range of pixel densities, much more than you would find in, say, the hdpi folder. – Ted Hopp Aug 28 '16 at 06:01
  • @pskink so why we use dp? we use dp cause 160dp is almost one inch in all device. – Mahdi Aug 28 '16 at 06:05
  • if you want exactly one inch use `1in` or `72pt` or (more or less) `25mm` – pskink Aug 28 '16 at 06:06
  • @TedHopp I wanna use sw folders cause they give us more detailed range as you know you can enter what width ever you want, so we can put dimens.xml for many phone size that finnaly lead to be more precise in be same sizes. – Mahdi Aug 28 '16 at 06:07
  • @pskink if I use in I will lose density of devices and as you know we put resources and drawables with many size and quality and my UI wont show proper. I know it is not good to use inch in sizes. :( – Mahdi Aug 28 '16 at 06:11
  • so do you want exactly the same size in inches or not? – pskink Aug 28 '16 at 06:11
  • yes but I wanna achieve this with choosing proper dp. please check my question. I wanna get the proper range of sw folders. this is my problem – Mahdi Aug 28 '16 at 06:13
  • ok you want some view to be 2 inches tall, so what is the difference if you write `layout_height="2in"` or ``layout_height="XXXdp"`` ? – pskink Aug 28 '16 at 06:16
  • @pskink so can you tell me why we use size in dp? – Mahdi Aug 28 '16 at 06:24
  • read [this](https://developer.android.com/guide/topics/resources/more-resources.html#Dimension) – pskink Aug 28 '16 at 06:27
  • @pskink i think that android get size in inch from density and screen resolution. so it will be the same problem if I use inch and it will not exact In all devices. inch = resolution / dpi – Mahdi Aug 28 '16 at 06:33
  • see http://androidxref.com/7.0.0_r1/xref/frameworks/base/core/java/android/util/TypedValue.java#345 – pskink Aug 28 '16 at 06:42
  • I think you need to test your assumptions. Android will scale a dp value based on the actual density of pixels on the particular device. The use of hdpi, xhdpi, etc. folders is for things like .png files that need to be different for different screen density categories. A dp value does not need to be different for hdpi than for xhdpi. It will always correspond to the physical size that it would have as pixels at 160 dpi. (That is, a value of 160dp will always be one inch, whether the actual device density is at the low or high end of the bucket.) – Ted Hopp Aug 28 '16 at 06:50
  • @pskink android recomend to not to use in or cm or mm. as you can test by put some value in some xml file. – Mahdi Aug 28 '16 at 07:07
  • this is because the exact size in inches, centimeters, points is not recommended and this is exactly what you are trying to achieve (the exact size in inches) – pskink Aug 28 '16 at 07:09
  • @TedHopp I know it and I don't use this for img and drawable. cause android resize it to just fit. but in dimension as I say we can create many dimension with dp and use for screen size – Mahdi Aug 28 '16 at 07:12
  • @pskink I wanna use dp in a way that my UI is same in many devices. not use same dp but with some change that finnaly shown in the same size in inch. – Mahdi Aug 28 '16 at 07:17
  • That's what dp does. Can you provide an example of a specific problem with using dp? – Ted Hopp Aug 28 '16 at 07:19
  • @TedHopp for example an Image frame with 300dp size will be (dp/dpi=inch) 300/200 = 1.5 inch in first device (200dpi) and in another device it will be 300/279=1.07 inch. (279dpi device) so as you see there is too much difference between high and end of range hdpi and your UI not just same in inch. aslo this problem is expandable in margin and another size. but it is pop when the size is big. – Mahdi Aug 28 '16 at 07:24
  • It now sounds like you're not talking about dp at all; you're talking about images that are a fixed number of pixels and are in the (say) drawable-hdpi folder. That's a completely different question than using dp in dimension and size values. Which is it? – Ted Hopp Aug 28 '16 at 07:39
  • @TedHopp my problem is when you use dp it is not exact size because of bucket ranges. it is not a matter of image size or margin size or what ever! when you use dp it been a difference from top of bucket and button of it and showing size is about to 1 inch difference as I told in example. but a dp supposed to be a same inch in all devices. (as you know one inch is 160 dp in all devices) for achieving for same inch in all devices i prefer to split buckets with help of sw folders and get them ( image or sizes) different dp size that finally lead to showing more same. – Mahdi Aug 28 '16 at 07:53
  • @pskink I know it is not exactly follow the real screen size! I try to create sw folder for this porous. for give many size that finally be more precise in final view in inch ( not dp my size dp are different but with ratio of screen widths) – Mahdi Aug 28 '16 at 08:02

1 Answers1

0

i had also similar requirement which i raised at this link Equal number of horizontal cards /items in all devices . Play store app is showing the same way in all the devices of different dpi's.

Community
  • 1
  • 1
krishnamn
  • 151
  • 3
  • 11