How to find screen size in fragment class

I watched this post: Get screen sizes in pixels when I tried to determine the screen size of a device in a fragment class. One answer was close to what I needed, but the only code that ended for me was:

WindowManager wm = (WindowManager) getView().getContext().getSystemService(Context.WINDOW_SERVICE); Display screen = wm.getDefaultDisplay(); 

after which I could use getHeight (); or another not obsolete term.

+4
source share
1 answer

Your questions have an answer! Just use getActvity () as the context in the fragment.

+8
source

Source: https://habr.com/ru/post/1401211/


All Articles