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.
You questions contains the answer! Just use getActvity() as the context in the fragment.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With