How do I find the screen size in a fragment class

Posted by thomas.cloud on Stack Overflow See other posts from Stack Overflow or by thomas.cloud
Published on 2012-03-13T17:17:16Z Indexed on 2012/03/23 23:30 UTC
Read the original article Hit count: 179

Filed under:
|

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.

© Stack Overflow or respective owner

Related posts about android

Related posts about android-fragments