0

My folder structure for layouts is like "layout-sw600dp-hdpi", " layout-sw480dp-hdpi" and so on.

At the moment when we want to find out under which category a particular device falls in, what we do is adding a layout file in every single folder with a different text. For an example if it is the file in " layout-sw600dp-hdpi" folder, then our text in layout file will also say "layout-sw600dp-hdpi".

Anyway our current method is very hard for us to find the device's size and make the screen accordingly.

Is there any other better way of knowing this?

PeakGen
  • 21,894
  • 86
  • 261
  • 463
  • Why do you want to know what is category of device? – piotrpo Jul 25 '16 at 17:30
  • 2
    See http://stackoverflow.com/questions/15061238/how-to-find-the-device-as-ldpi-mdpi-hdpi-or-xhdpi?rq=1 and http://stackoverflow.com/questions/5099550/how-to-check-an-android-device-is-hdpi-screen-or-mdpi-screen – s-hunter Jul 25 '16 at 17:31
  • @piotrpo otherwise how can I know in which phone my created layouts will run? – PeakGen Jul 25 '16 at 17:34
  • Just have a diff bool in values as per the device sizes u have in resources. Then just check in the app level or somewhere u can get access for the values. – mike20132013 Jul 25 '16 at 17:48

1 Answers1

0

You can take a look here: getting the screen density programmatically in android?

But... probably you don't need this answer.

If you're designing layout - you should do it in way that allows some flexibility (just as when you're designing web page). If you have to hard code some value (ex. margin), you can use dp units to allow it to scale automatically. If it's not enough - you can define this dimension in resources: https://developer.android.com/samples/BasicSyncAdapter/res/values/dimen.html Keep in mind that resources can have same structure as layouts - so you can put qualifiers like resources-sw600 or use one of other options (Android Studio has special dialog to allow creation of directories addressed to different hardware / software configurations.

If it's still not enough - you can use different layouts for different configurations, or maybe a look at fragments concept. https://developer.android.com/guide/components/fragments.html But still - at any of those points there is no need to know what is screen category (in terms of naming it).

Community
  • 1
  • 1
piotrpo
  • 12,398
  • 7
  • 42
  • 58