Android – how do I get the window width and height of an activity?

I have a listfragment, which adds two views in the onactivitycreated() method - a MapView general view (persistent title). I want the listview to be displayed under the MapView and title in portrait mode and on the right side of MapView and under the title in landscape mode. I also want the height (portrait) and width (landscape) of MapView to be a percentage of the available window size (minus the action bar, status bar and navigation bar – if present on the device). To achieve this, I believe I need to get the window size and calculate the appropriate height, width and layout margins for all three views. I tried some suggestions in similar problems, but the solution always returns the height / width of the device instead of the active window size

Any ideas? Thank you in advance

resolvent:

DisplayMetrics metrics = context.getResources().getDisplayMetrics();
int width = metrics.widthPixels;
int height = metrics.heightPixels;

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>