How to Get Device Height and Width at Runtime?

前端 未结 6 378
执念已碎
执念已碎 2020-12-09 15:06

I am developing an app in which I have to make our app to fit for every device - for both tablet and android mobiles. Now I want to get the device height and width at runtim

6条回答
  •  盖世英雄少女心
    2020-12-09 16:04

    In a Activity scope do:

    DisplayMetrics dm = new DisplayMetrics();
    getWindowManager().getDefaultDisplay().getMetrics(dm);
    int w = dm.widthPixels; // etc...
    

提交回复
热议问题