How to Get Device Height and Width at Runtime?

前端 未结 6 366
执念已碎
执念已碎 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:00

    You can get all the display related information using the class Display Metrics http://developer.android.com/reference/android/util/DisplayMetrics.html

    you would require

    DisplayMetrics metrics = new DisplayMetrics();
    getWindowManager().getDefaultDisplay().getMetrics(metrics);
    

    After this all the required information will be present in your metrics object.

    The other option is to call

    getActivity().getWindowManager().getDefaultDisplay().getWidth()
    getActivity().getWindowManager().getDefaultDisplay().getHeight()
    

提交回复
热议问题