
当我试图在这些方面比例得到可用的屏幕时,我的应用程序是很好的所有 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).
我的问题与此链接非常相似
解决方法 你可以使用decorvIEw获得可用的高度(即使在有或没有显示Navbar的galaxy S8上):07002
//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?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)