0

I'm setting up a gridview of 7 columns. I want it to have 6 rows and fill the screen. So, am trying to find the height of the screen excluding actionbar, statusbar and softkeys. Am planning to set this height divided by 6 as the height of each row. For some reason, the height am getting is not accurate.

DisplayMetrics metrics = context.getResources().getDisplayMetrics();
int height = metrics.heightPixels;
Jai
  • 217
  • 1
  • 4
  • 15

1 Answers1

0

This will give you correct screen dimensions

 Display display = getWindowManager().getDefaultDisplay();
        Point size = new Point();
        display.getSize(size);

        int width = size.x;
        int height = size.y;
RAHUL MAURYA
  • 306
  • 1
  • 9
  • Does this height include actionBar and all? – Jai Jun 12 '19 at 10:51
  • Yes and if you still face any problem you can check out this link https://stackoverflow.com/questions/24017774/how-to-get-usable-screen-width-and-height-in-android/24018031 – RAHUL MAURYA Jun 12 '19 at 10:55
  • Ok just check that link hope you find something – RAHUL MAURYA Jun 12 '19 at 11:03
  • Couldn't find any proper solution. What i end up doing is, i put a dummy view and get its height using globalLayoutListener and do the math with it. Might not be a good solution, but it worked for me! – Jai Jun 13 '19 at 05:55