ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

何获得s8可用的屏幕android?

2019-07-05 20:26:48  阅读:215  来源: 互联网

标签:android aspect-ratio uinavigationbar display


我是机器人中的菜鸟.关于可用高度为18:9设备的问题.
当我试图在这些方面比例得到可用的屏幕时,我的应用程序是很好的所有Android设备,但当在三星Galaxy s8编译时,它无法正常工作.
我试图获得可用的设备屏幕.
我已经尝试了在这些链接中的方法

https://stackoverflow.com/questions/43628047/how-to-support-189-aspect-ratio-in-android-apps

https://android-developers.googleblog.com/2017/03/update-your-app-to-take-advantage-of.html

我动态地使用

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

我试过了

private int getSoftButtonsBarHeight() {
        // getRealMetrics is only available with API 17 and +
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
            DisplayMetrics metrics = new DisplayMetrics();
            getWindowManager().getDefaultDisplay().getMetrics(metrics);
            int usableHeight = metrics.heightPixels;
            getWindowManager().getDefaultDisplay().getRealMetrics(metrics);
            int realHeight = metrics.heightPixels;
            if (realHeight > usableHeight)
                return realHeight - usableHeight;
            else
                return 0;
        }
        return 0;
    }

当我尝试设置params MATCH_PARENT高度时它工作正常.但我需要找到可用的高度像素来按比例设计我的其他视图.

实际上这些代码DisplayMetrics metrics = this.getResources().getDisplayMetrics();
     height = metrics.heightPixels;在我的Activity中工作但是当我尝试在另一个窗口中使用它时,我从FramaLayout扩展并添加到活动它不起作用.

这是我的代码块

public class StudentLoginActivity extends Activity {  ...
    FrameLayout.LayoutParams containerParams = new ScrollView.LayoutParams(width, height-sb);
    container = new FrameLayout(this);
    container.setLayoutParams(containerParams);
    container.setBackgroundColor(Color.rgb(248,248,248));
    loginStudentView = new StudentLoginView(this);
    container.addView(loginStudentView); ...

}

   public class StudentLoginView extends FrameLayout { ...
    FrameLayout.LayoutParams cp = new FrameLayout.LayoutParams(width, height);
    setLayoutParams(cp); ...

}

但是这个问题与android navigationBar高度有关,因为当我显示导航栏时没有问题但是如果我隐藏了navigationBar它没有调整大小应用程序仍在工作,屏幕上有一个导航栏(但我隐藏了navigationBar).

我的问题与此链接非常相​​似

07002

解决方法:

你可以使用decorview获得可用的高度(即使在有或没有显示NavBar的Galaxy S8上):

    //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

标签:android,aspect-ratio,uinavigationbar,display
来源: https://codeday.me/bug/20190705/1390623.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有