Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I find the screen size in a fragment class

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.

like image 854
thomas.cloud Avatar asked Feb 22 '23 04:02

thomas.cloud


1 Answers

You questions contains the answer! Just use getActvity() as the context in the fragment.

like image 104
Manfred Moser Avatar answered Mar 03 '23 06:03

Manfred Moser