How to get screen width and height

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

    From service:

    Display  display= ((WindowManager) getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
    int width = display.getWidth(); 
    int height = display.getHeight(); 
    
    0 讨论(0)
  • 2020-12-12 21:21

    This is what finally worked for me:

    DisplayMetrics metrics = this.getResources().getDisplayMetrics();
    int width = metrics.widthPixels;
    int height = metrics.heightPixels;
    
    0 讨论(0)
提交回复
热议问题