Reputation: 963
I was looking at this posting: Get screen dimensions in pixels 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.
Upvotes: 4
Views: 5326
Reputation: 29912
You questions contains the answer! Just use getActvity() as the context in the fragment.
Upvotes: 8