How to get screen width and height

后端 未结 14 1088
梦如初夏
梦如初夏 2020-12-12 20:31

I tried to use following code to get screen width and height in android app development:

Display display = getWindowManager().getDefaultDisplay(); 
int scree         


        
14条回答
  •  星月不相逢
    2020-12-12 20:56

    DisplayMetrics metrics = new DisplayMetrics();
    getWindowManager().getDefaultDisplay().getMetrics(metrics);
    
    int height = metrics.heightPixels;
    int width = metrics.widthPixels;
    

    i guess the code which you wrote is deprecated.

提交回复
热议问题