Android   发布时间:2022-04-28  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了何获得s8可用的屏幕android?大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
@H_674_4@ 我是机器人中的菜鸟.关于可用高度为18:9设备的问题.
我试在这些方面比例得到可用的屏幕时,我的应用程序是很好的所有 Android设备,但当在三星Galaxy s8编译时,它无法正常工作.
我试图获得可用的设备屏幕.
我已经尝试了在这链接中的@L_772_4@

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).

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

解决方法

你可以使用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

大佬总结

以上是大佬教程为你收集整理的何获得s8可用的屏幕android?全部内容,希望文章能够帮你解决何获得s8可用的屏幕android?所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。