简体   繁体   English

如何确定正在使用哪个值文件夹

[英]How to determine which values folder is being used

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. 当您拥有多个带有不同限定词的value文件夹时(如我现在使用的那样)。 I am looking for a way to add some logging that will show me exactly which values folder is being used. 我正在寻找一种添加一些日志记录的方法,该日志记录将向我确切显示正在使用哪个values文件夹。 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;

If you name your directories as values-small, values-normal, values-large and values-xlarge, you can use: 如果将目录命名为values-small,values-normal,values-large和values-xlarge,则可以使用:

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;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM