Android multiple screen sizes with same density

后端 未结 6 839
你的背包
你的背包 2020-11-29 16:49

I\'m confused regarding the densities. I see that with medium density, the screen resolution could be either 320x480, 480x800, or 480x854. So if I have an image thats 300px

6条回答
  •  伪装坚强ぢ
    2020-11-29 17:34

    Actually the code to calculate physical screen size for devices is the following one:

    DisplayMetrics dm = new DisplayMetrics();
    
    getWindowManager().getDefaultDisplay().getMetrics(dm);
    
    double x = Math.pow(dm.widthPixels/dm.xdpi,2);
    
    double y = Math.pow(dm.heightPixels/dm.ydpi,2);
    
    double screenInches = Math.sqrt(x+y);
    

提交回复
热议问题