Android: Showing wrong screen resolution

前端 未结 6 1032
说谎
说谎 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

    Try to use this:

    width = getResources().getDisplayMetrics().widthPixels;
    height = getResources().getDisplayMetrics().heightPixels;
    

    Seems like you're getting the pixel after division of the density ( 1.5 ) of Galaxy S.

    480 / 1.5 = 320
    799.5 / 1.5 = 533
    

    Edit:

    density = getResources().getDisplayMetrics().density;
    

提交回复
热议问题