如何获得景观中的可用高度?

发布于 2024-12-09 12:49:45 字数 473 浏览 5 评论 0原文

我有一个带有图像视图的布局。该图像视图的比例应为 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 宽度。所以我需要获取屏幕的高度减去状态/通知栏。

我在

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

I have a layout with an imageview. This imageview should have a 4/3 ratio. In portrait mode i get the width of the screen then compute the height and set the imageView dimensions.

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;

This part works great.

In landscape mode i need to set the imageView width according to the available height. So i need to get the height of the screen minus the status/notification bar.

I saw the value of 48px for the bar in this question. Is it a standard size ?

What the best solution to get the available height regardless of the used device ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

留蓝 2024-12-16 12:49:45
    Display d = ((Activity) mContext).getWindowManager()
            .getDefaultDisplay();
    int h = d.getHeight();
    int w = d.getWidth();

肖像 h > w 和横向 w >小时

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

in portrait h > w and in landscape w > h

挽清梦 2024-12-16 12:49:45

如果您要创建一个活动,那么您必须有某种布局。获取它的根组件,并检索它的大小(getWidth、getHeight)。这将是不包括状态栏的可用宽度和高度。

If you're creating an Activity, than you have to have some sort of layout. Get it's root component, and retrieve it's size (getWidth, getHeight). That'll be the available width and height without counting the status bar.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文