【问题标题】:android Navigation Bar hiding and persantage of usable screen overlapandroid导航栏隐藏和可用屏幕重叠的persantage
【发布时间】:2017-08-20 01:02:30
【问题描述】:

我的问题是关于可用屏幕的 persantage 。我的应用程序运行正常,但我假设如果我改变屏幕尺寸(例如 Galaxy s8+),它就会关闭。

这就是正常工作的方式

强文本

这是错误的

与 NavigationBar 相关的问题。 我尝试设置 MACHPARENT 参数,通常我以编程方式使用 DisplayMetrics metrics = this.getResources().getDisplayMetrics(); 宽度=metrics.widthPixels; height = metrics.heightPixels - Utils.getStatusBarHeight(getContext());这段代码。但是当我隐藏导航栏时,它在 Galaxy s8+ 中不起作用。 有谁可以帮助我的折叠是什么?

编辑。 我的意思是我的屏幕高度不起作用。

【问题讨论】:

  • 你找到这个问题的答案了吗?我遇到了同样的问题。 S8 导航栏弄乱了我的应用程序的测量值。 UI 看起来完全不对了。
  • 如果您找到任何解决此问题的方法,请在此处发布

标签: android height width uinavigationbar android-fullscreen


【解决方案1】:

我遇到了同样的问题,可以用 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

【讨论】:

    猜你喜欢
    • 2023-02-12
    • 2020-11-15
    • 1970-01-01
    • 2019-01-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多