【发布时间】:2018-01-30 02:56:35
【问题描述】:
我是安卓的菜鸟。我关于 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;
}
当我尝试设置参数 MATCH_PARENT 高度时,它运行良好。但我需要找到可用的高度像素来按比例设计我的其他视图。
实际上,这些代码 DisplayMetrics metrics = this.getResources().getDisplayMetrics();
height = metrics.heightPixels ; 在我的 Activity 中工作,但是当我尝试在从 FramaLayout 扩展并添加到 Activity 的另一个窗口中使用它时,它不起作用。
这是我的代码块
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,它不是调整大小的应用程序仍然在工作,屏幕上有一个导航栏(但我隐藏了导航栏)。
我的问题和这个链接很相似
android Navigation Bar hiding and persantage of usable screen overlap
【问题讨论】:
-
什么叫可用高度?
-
第二个链接粘贴错误。
标签: android uinavigationbar display aspect-ratio