android - 如何在景观中获得可用高度?

标签 android height screen

我有一个带有 ImageView 的布局。这个 imageview 应该有一个 4/3 的比例。在纵向模式下,我获取屏幕的宽度,然后计算高度并设置 imageView 尺寸。

int[] tailles       = new int[2];
DisplayMetrics dm   = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(dm);
int widthScreen     = dm.widthPixels;
tailles[0]          = widthScreen;
tailles[1]          = (tailles[0]*3)/4;

这部分效果很好。

在横向模式下,我需要根据可用高度设置 imageView 宽度。所以我需要得到屏幕的高度减去状态/通知栏。

我在 this question 中看到了 48px 的值.是标准尺寸吗?

无论使用什么设备,获得可用高度的最佳解决方案是什么?

最佳答案

    Display d = ((Activity) mContext).getWindowManager()
            .getDefaultDisplay();
    int h = d.getHeight();
    int w = d.getWidth();

纵向 h > w 和横向 w > h

关于android - 如何在景观中获得可用高度?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7737115/

相关文章:

javascript - 如果屏幕宽度小于 960 像素,则将屏幕宽度添加到类中

android - 在 Android 中以编程方式使用屏幕截图时保存空白文件

android - 如何在 Eclipse 中使用 Legacy Apache 以支持 Android M

text - 计算 SVG 文本高度和宽度的正确方法

c# - 可玩高度图

ios - 高度等于 Swift 中 CustomCell 的最大高度的 CollectionView

video - 是否有用于截屏压缩的良好开放编解码器

java - 如何在 Java、Android 中使用 KSOAP2 获取字符串数组?

android - 何时在 android 原生框架 (AOSP) 中使用弱指针 (wp)

android - 是否可以在单个项目/应用程序中为发布和 Debug模式制作不同的 Firebase 数据库?