How to get Screen metrics outside an Activity?

后端 未结 4 1766
名媛妹妹
名媛妹妹 2021-02-04 01:59

I have a Generic Pool that i am making here:

public class FruitPool extends GenericPool {
// ======================================================         


        
4条回答
  •  無奈伤痛
    2021-02-04 02:46

    Here is the api I have written to get the screen width, you need a context to get the window system service. Similarly you can get the height.

    int getWindowWidth() {
        WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
        Display display = wm.getDefaultDisplay();
        Point size = new Point();
        display.getSize(size);
        return size.x;
    }
    

提交回复
热议问题