is the screen from this device belongs to ldpi (or mdpi or hdpi) density?
-
27-04-2021 - |
Question
I want to write a function like this
public boolean isThisScreenWithHdpiDensity(){
return true/false;
}
but I do not know how to calculate this at run time programmatic-ally
Solution
Use this inside your function:
DisplayMetrics metrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(metrics);
switch(metrics.densityDpi){
case DisplayMetrics.DENSITY_LOW:
break;
case DisplayMetrics.DENSITY_MEDIUM:
break;
case DisplayMetrics.DENSITY_HIGH:
break;
}
OTHER TIPS
public boolean isThisScreenWithHdpiDensity()
{
DisplayMetrics metrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(metrics);
if(metrics.density == DisplayMetrics.DENSITY_HIGH)
{
return true;
}
return false;
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow