android Navigation Bar hiding and persantage of usable screen overlap

ぐ巨炮叔叔 提交于 2019-12-23 15:44:52

问题


My problem is about persantage of usable screen . My application working well normally but ı assume that if ı change dimension of screen (for example galaxy s8+) it is down.

this is how is working fine

strong text

and this is the wrong one

the problem related with NavigationBar. I tried to set MACHPARENT params and normally I use programmatically DisplayMetrics metrics = this.getResources().getDisplayMetrics(); width = metrics.widthPixels; height = metrics.heightPixels - Utils.getStatusBarHeight(getContext()); this code. But it is not working in Galaxy s8+ when I hide navigationBar. Does anyone can help me what is my fold?

edit. I mean height of my screen doesnt work.


回答1:


I had the same problem and could solve this with the decorview:

    //Get the correct screen size even if the device has a hideable navigation bar (e.g. the Samsung Galaxy S8)
    View decorView = getWindow().getDecorView(); //if you use this in a fragment, use getActivity before getWindow()
    Rect r = new Rect();
    decorView.getWindowVisibleDisplayFrame(r);
    int screenHeight = r.bottom; // =2220 on S8 with hidden NavBar and =2076 with enabled NavBar
    int screenWidth = r.right; // =1080 on S8


来源:https://stackoverflow.com/questions/45777581/android-navigation-bar-hiding-and-persantage-of-usable-screen-overlap

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!