【问题标题】:Get the correct screen display size on Galaxy S8在 Galaxy S8 上获得正确的屏幕显示尺寸
【发布时间】:2018-02-22 11:21:54
【问题描述】:

在我的应用中,我目前使用 windowManager.getDefaultDisplay() 来确定屏幕大小。

使用新的三星 S8 导航栏,可以使用左下角的“点”来显示和隐藏,我可以得到相同的显示大小来显示或隐藏导航栏。它总是返回显示大小,就像显示导航栏一样 - 我希望在隐藏导航栏时得到 1080x2220,但总是得到 1080x2076。

有什么方法可以通过编程方式区分案例并获得正确的屏幕尺寸,以便正确显示我的应用程序?

【问题讨论】:

  • 我不太熟悉这种情况,但是有没有办法获得导航栏(例如getNavigationBar())并检查isVisible() 是否?如果是这样,您可以获取导航栏的高度并将其添加到屏幕上吗?或者导航栏区域是否以某种方式“受限”而不考虑可见性?
  • 你试过用Immersive Full-Screen Mode吗?

标签: android screen-size samsung-s8


【解决方案1】:

我遇到了和你一样的问题,我找到的解决方法是测量content root view的高度: p>

findViewById(android.R.id.content).getHeight()

希望对你有所帮助。

点击此处了解有关android.R.id.content的更多详细信息

【讨论】:

    【解决方案2】:

    我也遇到了同样的问题,但是内容根视图的解决方案对我不起作用(我得到的高度是 2148)。

    但我可以用 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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-02-21
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多