大佬教程收集整理的这篇文章主要介绍了何获得s8可用的屏幕android?,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
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).
我的问题与此链接非常相似
//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,请注明来意。