How to get screen width and height

后端 未结 14 1069
梦如初夏
梦如初夏 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 21:06

           /*
            *DisplayMetrics: A structure describing general information about a display, such as its size, density, and font scaling.
            * */
    
     DisplayMetrics metrics = getResources().getDisplayMetrics();
    
           int DeviceTotalWidth = metrics.widthPixels;
           int DeviceTotalHeight = metrics.heightPixels;
    

提交回复
热议问题