2017-04-17 93 views
0

我是android開發中的新手。 我已經創建了一個android應用程序,大部分設備設計看起來都很好。 1080x1920分辨率的設備工作正常。但是,一些設備Nexus 5x和LeEco-2(兩者具有相同的分辨率)設計(UI)在這些設備中並不像預期的那樣。如何使用1080x1920:420 dpi - Android studio

我需要爲這些設備使用哪個資源文件夾?

enter image description here

+0

看到邏輯http://stackoverflow.com/questions/32860815/how-to-define-dimens-xml-for-every - 不同的屏幕尺寸,在功能的Android/32861248#32861248 –

回答

0

調用此method知道哪個屏幕尺寸實際上是該設備!一些設備從xxxhdpi獲得值從sw800dp某些GET(或任何其它smallest width文件夾)

public int differentDensityAndScreenSize(Context context) { 
     int value = 20; 
     String str = ""; 
     if ((context.getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_SMALL) { 
      switch (context.getResources().getDisplayMetrics().densityDpi) { 
       case DisplayMetrics.DENSITY_LOW: 
        str = "small-ldpi"; 
        value = 20; 
        break; 
       case DisplayMetrics.DENSITY_MEDIUM: 
        str = "small-mdpi"; 
        value = 20; 
        break; 
       case DisplayMetrics.DENSITY_HIGH: 
        str = "small-hdpi"; 
        value = 20; 
        break; 
       case DisplayMetrics.DENSITY_XHIGH: 
        str = "small-xhdpi"; 
        value = 20; 
        break; 
       case DisplayMetrics.DENSITY_XXHIGH: 
        str = "small-xxhdpi"; 
        value = 20; 
        break; 
       case DisplayMetrics.DENSITY_XXXHIGH: 
        str = "small-xxxhdpi"; 
        value = 20; 
        break; 
       case DisplayMetrics.DENSITY_TV: 
        str = "small-tvdpi"; 
        value = 20; 
        break; 
       default: 
        str = "small-unknown"; 
        value = 20; 
        break; 
      } 

     } else if ((context.getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_NORMAL) { 
      switch (context.getResources().getDisplayMetrics().densityDpi) { 
       case DisplayMetrics.DENSITY_LOW: 
        str = "normal-ldpi"; 
        value = 82; 
        break; 
       case DisplayMetrics.DENSITY_MEDIUM: 
        str = "normal-mdpi"; 
        value = 82; 
        break; 
       case DisplayMetrics.DENSITY_HIGH: 
        str = "normal-hdpi"; 
        value = 82; 
        break; 
       case DisplayMetrics.DENSITY_XHIGH: 
        str = "normal-xhdpi"; 
        value = 90; 
        break; 
       case DisplayMetrics.DENSITY_XXHIGH: 
        str = "normal-xxhdpi"; 
        value = 96; 
        break; 
       case DisplayMetrics.DENSITY_XXXHIGH: 
        str = "normal-xxxhdpi"; 
        value = 96; 
        break; 
       case DisplayMetrics.DENSITY_TV: 
        str = "normal-tvdpi"; 
        value = 96; 
        break; 
       default: 
        str = "normal-unknown"; 
        value = 82; 
        break; 
      } 
     } else if ((context.getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_LARGE) { 
      switch (context.getResources().getDisplayMetrics().densityDpi) { 
       case DisplayMetrics.DENSITY_LOW: 
        str = "large-ldpi"; 
        value = 78; 
        break; 
       case DisplayMetrics.DENSITY_MEDIUM: 
        str = "large-mdpi"; 
        value = 78; 
        break; 
       case DisplayMetrics.DENSITY_HIGH: 
        str = "large-hdpi"; 
        value = 78; 
        break; 
       case DisplayMetrics.DENSITY_XHIGH: 
        str = "large-xhdpi"; 
        value = 125; 
        break; 
       case DisplayMetrics.DENSITY_XXHIGH: 
        str = "large-xxhdpi"; 
        value = 125; 
        break; 
       case DisplayMetrics.DENSITY_XXXHIGH: 
        str = "large-xxxhdpi"; 
        value = 125; 
        break; 
       case DisplayMetrics.DENSITY_TV: 
        str = "large-tvdpi"; 
        value = 125; 
        break; 
       default: 
        str = "large-unknown"; 
        value = 78; 
        break; 
      } 

     } else if ((context.getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_XLARGE) { 
      switch (context.getResources().getDisplayMetrics().densityDpi) { 
       case DisplayMetrics.DENSITY_LOW: 
        str = "xlarge-ldpi"; 
        value = 125; 
        break; 
       case DisplayMetrics.DENSITY_MEDIUM: 
        str = "xlarge-mdpi"; 
        value = 125; 
        break; 
       case DisplayMetrics.DENSITY_HIGH: 
        str = "xlarge-hdpi"; 
        value = 125; 
        break; 
       case DisplayMetrics.DENSITY_XHIGH: 
        str = "xlarge-xhdpi"; 
        value = 125; 
        break; 
       case DisplayMetrics.DENSITY_XXHIGH: 
        str = "xlarge-xxhdpi"; 
        value = 125; 
        break; 
       case DisplayMetrics.DENSITY_XXXHIGH: 
        str = "xlarge-xxxhdpi"; 
        value = 125; 
        break; 
       case DisplayMetrics.DENSITY_TV: 
        str = "xlarge-tvdpi"; 
        value = 125; 
        break; 
       default: 
        str = "xlarge-unknown"; 
        value = 125; 
        break; 
      } 
     } 
// The Toast will show the Device falls in Which Categories. 
     Toast.makeText(MainActivity.this, ""+str, Toast.LENGTH_SHORT).show(); 

     return value; 
    }