How do I find the screen size in a fragment class
- by thomas.cloud
I was looking at this posting: Android: How to get screen dimensions when I was trying to determine the size of the device's screen while in a fragment class. One answer was close to what I needed but the only code that ended up working for me was:
WindowManager wm = (WindowManager) getView().getContext().getSystemService(Context.WINDOW_SERVICE);
Display screen = wm.getDefaultDisplay();
whereupon I could then use getHeight(); or another non-deprecated term. I realize this is exactly the same as the other site except this way you don't have define your context on a separate line.