0

I change from Eclipse to Android Studio. I'm facing a problem with the densities of the Emulators. For example, in Eclipse the Samsung S4 was density xxhdpi but in Android Studio is xhdpi. Samsung S4: 4,99' - 1080 x 1920.

This is my code:

Float density = getResources().getDisplayMetrics().density;

if(density >= 1.0 && density < 1.5){ //mdpi
 ...
} else if(density >= 1.5 && density < 2.0){ //hdpi
 ...
} else if(density >= 2.0 && density < 3.0){ //xhdpi
 ...
} else if(density >= 3.0 && density < 4.0){ //xxhdpi
 ...
} else if(density >= 4.0){ //xxxhdpi
 ...
}

Value of density is 2.625. So enters in the xhdpi case, but I need to enter in the xxhdpi! What is the problem? Is there a better way to do this?.

Thanks

user3240604
  • 407
  • 1
  • 8
  • 22
  • Do you really have this chain of `if`s somewhere in your code? If so, you are doing most likely something wrong or suboptimal. – Henry Feb 03 '17 at 14:26
  • Yes I have. Why? For example, I use dp, wrap_content, etc to try to work in every screen but sometimes I need to adjust manually some sizes or positions – user3240604 Feb 03 '17 at 14:37
  • This is normally done by putting the values into a resource file. You can have different versions for different screen sizes or densities. The code itself is then clean, just get the resource value. – Henry Feb 03 '17 at 15:36
  • Can you explain more or show some example code? – user3240604 Feb 03 '17 at 17:40
  • Look here https://developer.android.com/guide/topics/resources/index.html – Henry Feb 04 '17 at 05:17
  • what i have to look? That is big... – user3240604 Feb 06 '17 at 15:14
  • @user3240604 add an example of how you "adjust manually some sizes or positions". – manfcas Feb 10 '17 at 21:18

1 Answers1

0

Put this code in your manifest.xml

   <supports-screens android:anyDensity="true"
    android:largeScreens="true"
    android:normalScreens="true"
    android:resizeable="true"
    android:smallScreens="true"
    android:xlargeScreens="true"/>

Hope it will help you.

MAS. John
  • 582
  • 6
  • 22