0

I wanted to create dimensions (dimen.xml) specific for a device in android. I tried to look at the display information and could find the Physical pixel density is 294 dpi, with width and height (160.42 x 160.15). I am confused in renaming the values folder( values-sw294 or values-sw160) so that the dimensions only apply to that device(I have a common dimens.xml in values folder).

I got to know the screen density of the device using the following command.

 $ dumpsys display | grep mBaseDisplayInfo
    mBaseDisplayInfo=DisplayInfo{"Built-in Screen", uniqueId "local:0", app 1280 x 720, real 1280 x 720, lar
gest app 1280 x 720, smallest app 1280 x 720, mode 1, defaultMode 1, modes [{id=1, width=1280, height=720, f
ps=30.0}], colorMode 0, supportedColorModes [0], hdrCapabilities android.view.Display$HdrCapabilities@a69d63
08, rotation 0, density 294 (160.42105 x 160.15764) dpi, layerStack 0, appVsyncOff 1000000, presDeadline 333
33333, type BUILT_IN, state ON, FLAG_SECURE, FLAG_SUPPORTS_PROTECTED_BUFFERS}
Angus
  • 12,133
  • 29
  • 96
  • 151
  • 1
    `-sw` has nothing to do with density. `-sw` is for screen size. – CommonsWare Jun 05 '20 at 22:10
  • @CommonsWare : So inorder to create a separate dimensions for the device, I need to get the screen width of the device ? .. Not sure, which values I need to pick from the above 1280 x 720 or 160.42 x 160.15 as per the display info – Angus Jun 05 '20 at 22:13
  • "inorder to create a separate dimensions for the device" -- to be honest, that statement does not make much sense to me, and it is not really a concept in Android. You can have different resources for different scenarios, such as based on screen size, but that has nothing to do with this specific device. Any device that fits the scenario would also use those different resources. So, stop thinking in terms of this device, and determine what it is about the device that is causing you to want different dimension resources. – CommonsWare Jun 05 '20 at 22:18
  • 1
    Once you decide what the reason is for the different dimensions, then we can figure out the right way to handle it. That might be through some sort of resource set qualifier (e.g., `-sw`), or it might need to be in Java/Kotlin code. – CommonsWare Jun 05 '20 at 22:18
  • @Commonsware : I wanted to create a separate resources dimen.xml folder for small screen size as my device. And I got confused with the screen size and density. I assume, that I need to find the screen size and append the values folder with the screen size as the name – Angus Jun 05 '20 at 22:42
  • @CommonsWare : I came across this article on finding the screen size, https://stackoverflow.com/questions/4743116/get-screen-width-and-height-in-android , but I was trying to find through adb commands, rather doing the code changes. – Angus Jun 05 '20 at 22:44
  • @CommonsWare : I ran the dumpsys window command, to check the screen size. mCurConfiguration={1.0 ?mcc?mnc [en_US] ldltr sw391dp w696dp h367dp 294dpi nrml long land finger 12key/v/h -nav/h s.5} I believe, I need to use values-sw391 as values folder to provide the dimensions for the appropriate screensize. – Angus Jun 05 '20 at 22:52
  • 1
    "I wanted to create a separate resources dimen.xml folder for small screen size as my device" -- that's not really possible. The resource set qualifiers for size, like `-sw`, work for a specific size *or larger*. So, for example, if you have `res/values/` and `res/values-sw480dp/`, devices whose smallest width is 3" *or larger* will use `res/values-sw480dp/`, while smaller devices would use `res/values/`, for a resource that exists in both locations. – CommonsWare Jun 05 '20 at 22:59
  • @CommonsWare : Thanks for clarifying that. I could understand now. The problem in my devices is that since it has more width and less height one among the 4 view was getting chopped off, Hence I was asked to override the dimension values for small screen sizes as my device. The only difference I see is the height of my device is small, it has got a good width, and hence the 4 elements were not fitting in. But other devices were having a good height to accommodate the 4 views, but less width. – Angus Jun 05 '20 at 23:29
  • So, as you clearly mentioned above, I cant use sw- in this case. And I see my configuration in the device using the dumpsys command, as " mCurConfiguration={1.0 ?mcc?mnc [en_US] ldltr sw391dp w696dp h367dp 294dpi nrml long land finger 12key/v/h -nav/h s.5}" . Will using values-h367 in res/ folder will make a difference ? – Angus Jun 05 '20 at 23:29
  • 1
    There are over 26,000 Android device models. These come with a wide range of screen sizes and aspect ratios. You are going to need to create a more flexible UI, to be able to accommodate these. And, there are environments like Chrome OS, where the user can resize the window to arbitrary heights and widths. A strategy of "use a magic set of dimensions for this one device" is not going to work. – CommonsWare Jun 05 '20 at 23:35
  • 1
    You might consider asking a separate Stack Overflow question, where your [mcve] shows the layout resource along with screenshots of what is working and what is not working. Perhaps people here can provide advice for how to improve the flexibility of that layout. – CommonsWare Jun 05 '20 at 23:37

0 Answers0