How to Get Device Height and Width at Runtime?

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

    this is how you get the available screen dimensions. This will get you not the raw pixel size but the available space of your window/activity.

        Point outSize = new Point();
        getWindowManager().getDefaultDisplay().getSize(outSize);
    

    Also you can have different layout xml files for both landscape and portrait. Put your xml for portrait in res/layout-port. Layout for landscape can be put into res/layout-land. You should read up how android handles resources

提交回复
热议问题