3

Periodically, I will run in to an issue where a layout file will not read values from any dimensions file. This comes up when you have multiple values folders with different qualifiers, as I am working with now. I am looking for a way to add some logging that will show me exactly which values folder is being used. I have found several examples that allow you to get screen information, such as the following, and am hoping there is some method that will return which values folder / qualifier is being used as well.

int screenDensityDPI = getResources().getConfiguration().densityDpi;
int screenWidth = getResources().getConfiguration().screenWidthDp;
int smallestScreenWidth =getResources().getConfiguration().smallestScreenWidthDp;
bboursaw73
  • 1,128
  • 2
  • 13
  • 26
  • To clarify, the issue is not that I have values folders with different qualifiers, I know that is ok. My theory is that when the layout can't find an "appropriate" match, it does not appear to be using the closes match as the docs state for many things. It just simply displays the values from the dimens file contained in the first values folder. Even though this is occurring, the layout does not change/adapt to the values modified in that dimens file. – bboursaw73 Jul 12 '16 at 01:55

1 Answers1

0

If you name your directories as values-small, values-normal, values-large and values-xlarge, you can use:

int screenSize = getResources().getConfiguration().screenLayout &
                            Configuration.SCREENLAYOUT_SIZE_MASK;

switch (screenSize) {
  case Configuration.SCREENLAYOUT_SIZE_SMALL:
      // values-small directory
      break;
  case Configuration.SCREENLAYOUT_SIZE_NORMAL:
      // values-normal directory
      break;
  case Configuration.SCREENLAYOUT_SIZE_LARGE:
      // values-large directory
      break;
  case Configuration.SCREENLAYOUT_SIZE_XLARGE:
      // values-xlarge directory
      break;
}
filipebarretto
  • 1,842
  • 1
  • 13
  • 27
  • Thank you for the code, this is definitely helpful, but not exactly what I'm after. The issue with these is I sometimes run in to devices which fall in to the same bucket yet result in differences in layout between the two devices. I believe the issue is some combination of both size and density, so my preferred way to handle this is to use two resource qualifiers, swdp-density, such as values-sw320dp-xhdpi – bboursaw73 Jul 12 '16 at 05:22
  • Hmm not sure I understood curectly. But if I did, for debugging purposes you can follow the answer from this question: http://stackoverflow.com/questions/17157220/easiest-way-to-know-programmatically-which-resources-folder-is-used-based-on-s Add a foldername to each string.xml and validate it like this in your code. If this is what you are looking for, let me know that ill update my answer. – filipebarretto Jul 12 '16 at 18:18