If you want the display dimensions in pixels you can use getSize: Display display = getWindowManager().getDefaultDisplay() Legacy size that Display#getSize reportsįinal Size legacySize = new Size(bounds.width() - insetsWidth, Int insetsHeight = insets.top + insets.bottom Int insetsWidth = insets.right + insets.left Insets insets = windowInsets.getInsetsIgnoringVisibility(() GetWindowManager().getDefaultDisplay().getMetrics(metrics) Īpi level 30 update final WindowMetrics metrics = windowManager.getCurrentWindowMetrics() įinal WindowInsets windowInsets = metrics.getWindowInsets() DisplayMetrics metrics = new DisplayMetrics() This objects contains the fields like heightPixels, widthPixels. The first two lines of code gives you the DisplayMetrics objecs. It is deprecated, and you should try the following code instead. One way is: Display display = getWindowManager().getDefaultDisplay() The listener's callback will be called when the layout will have been laid out. It may not answer your question, but it could be useful to know (I was looking for it myself when I came to this question) that if you need a View's dimension but your code is being executed when its layout has not been laid out yet (for example in onCreate() ) you can setup a ViewTreeObserver.OnGlobalLayoutListener with View.getViewTreeObserver().addOnGlobalLayoutListener() and put the relevant code that needs the view's dimension there.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |