Width, Smallest Width and Height

Did you know you can check the smallest width of whatever virtual device your using with this code?

Configuration config = getResources().getConfiguration();
config.smallestScreenWidthDp

Because i sure as heck didn’t.

Also you can get the current width and height with this:

DisplayMetrics displayMetrics = this.getResources().getDisplayMetrics();
            float dpHeight = displayMetrics.heightPixels / displayMetrics.density;
            float dpWidth = displayMetrics.widthPixels / displayMetrics.density;
            Log.d("dpHeight-----",String.valueOf(dpHeight));
            Log.d("dpWidth------",String.valueOf(dpWidth));

Be careful though as this apparently changes depending on if the device is in portrait or landscape mode.

Leave a Reply

%d bloggers like this: