Android: Showing wrong screen resolution

前端 未结 6 1026
说谎
说谎 2020-11-29 10:19

I was trying to get the screen resolution of android phones,using this code

    DisplayMetrics dm = new DisplayMetrics();
    getWindowManager().getDefaultDi         


        
6条回答
  •  攒了一身酷
    2020-11-29 11:16

    Here is how i did it:

    Display dis = getWindowManager().getDefaultDisplay();
    Point point= new Point();
    dis.getSize(point);
    int width = point.x;
    int height = point.y;
    

    When not in an Activity:

    WindowManager wm = (WindowManager) ctx.getSystemService(Context.WINDOW_SERVICE);
    Display display = wm.getDefaultDisplay();
    

    Before getSize was introduced (in API level 13), you could use the getWidth and getHeight methods that are now deprecated:

    Display display = getWindowManager().getDefaultDisplay(); 
    int width = display.getWidth();  // deprecated
    int height = display.getHeight();  // deprecated
    

提交回复
热议问题