how to get total screen size on an android device programmatically

后端 未结 8 1600
旧巷少年郎
旧巷少年郎 2021-01-02 11:42

if i use the code shown here to get the total screen size it is always short on height to the total screen size as shown in the documented specs for the device. for example

8条回答
  •  生来不讨喜
    2021-01-02 11:52

        int Measuredwidth = 0;
        int Measuredheight = 0;
        Point size = new Point();
        WindowManager w = getWindowManager();
    
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2) {
            w.getDefaultDisplay().getSize(size);
            Measuredwidth = size.x;
            Measuredheight = size.y;
        } else {
            Display d = w.getDefaultDisplay();
            Measuredwidth = d.getWidth();
            Measuredheight   = d.getHeight();;
        }
    

提交回复
热议问题