0

This may end up being a "yes" or "no" question...

Starting in Nougat (maybe marshmallow?), users can change the display size of their device. Specifically on the Galaxy S8 and S8+, the user can change the display resolution.

I've seen the solutions here: Get Screen width and height

QUESTION: Do these solutions give the actual height/width of the screen regardless of changed resolution or do they give the adjusted height/width of the screen if resolution changed?

If the first, how do I get the adjusted height/width?

Psest328
  • 6,575
  • 11
  • 55
  • 90

1 Answers1

2

Interesting question. It gives me adjusted dimensions in pixels. I have tested it now in my Pixel running Android O.

Method 1:

        DisplayMetrics displayMetrics = new DisplayMetrics();
        getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
        int height = displayMetrics.heightPixels;
        int width = displayMetrics.widthPixels;

Method 2:

        Configuration configuration = getResources().getConfiguration();
        int screenWidthDp = configuration.screenWidthDp; 
        int screenHeightDp = configuration.screenHeightDp;
        int smallestScreenWidthDp = configuration.smallestScreenWidthDp;

Both methods returned the adjusted dimensions. The first method returns the device screen dimensions. The second method returns the dimensions of the app screen. These two result would vary when there are two apps open in multi-window mode.

Bob
  • 13,447
  • 7
  • 35
  • 45