android中如何区分480 * 800和480 * 854屏幕分辨率的布局?

发布于 2024-10-28 02:50:48 字数 264 浏览 1 评论 0原文

在其中一个应用程序中,我需要确保 UI 组件将放置在所有屏幕分辨率设备中的正确位置。我已经浏览了 Android 开发者网站上的支持多种屏幕分辨率教程。基于此,我似乎可能必须为小屏幕、普通屏幕和大屏幕设备创建单独的布局文件。现在的问题是,即使在大屏幕中,也有不同的分辨率,例如 480 * 800 和 480 * 854。在屏幕中,组件会稍微错位。我将顶部边距设置为 100 倾角,然后对于 480 * 800,它显示正确,但对于 480 * 854,它稍微错位。

有人可以告诉我现在该如何处理吗?

In one of the application I need to make sure that UI components will be placed at proper position in all the screen resolution devices. I have gone through the support multiple screen resolutions tutorial on android developer site. Based on that it seems I may have to create separate layout files for small, normal and large screen devices. Now, the issue in this is that even in large screens there are different resolutions such as 480 * 800 and 480 * 854. In the screen the components gets misplaced slightly. I have set top margin as 100 dip then for 480 * 800 it appears properly but for 480 * 854 it is misplaced slightly.

Can someone let me know how to handle this now?

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

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

发布评论

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

评论(2

怎樣才叫好 2024-11-04 02:50:48

这两种分辨率都被视为布局长,因此您必须根据设备的高度和宽度手动设置布局。

根据我的观点,这是最好的解决方案。我为我的应用程序应用了相同的解决方案。

示例

        DisplayMetrics dm = new DisplayMetrics();
        getWindowManager().getDefaultDisplay().getMetrics(dm);
        height = dm.heightPixels;
        width = dm.widthPixels;

        if (height == 854 || width == 480) 
        {
              // Your view 
        }
        else
        {
              // Your VIew
        }

您必须在活动的 onCreate() 方法中检查上述条件。

both the resolutions are considered under the layout-long, so you have to set the layout as per the device's height and width manually.

As per my view this is the best solution . I applied the same solution for my application .

Example

        DisplayMetrics dm = new DisplayMetrics();
        getWindowManager().getDefaultDisplay().getMetrics(dm);
        height = dm.heightPixels;
        width = dm.widthPixels;

        if (height == 854 || width == 480) 
        {
              // Your view 
        }
        else
        {
              // Your VIew
        }

You have to check the above condition in onCreate() method of acivity..

自找没趣 2024-11-04 02:50:48

应该可以区分 WVGA854 和 WVGA800

通过使用res/drawable-hdpi-long/
res/drawable-hdpi-notlong/

但我肯定会建议您设计布局,以便它足够强大,可以为这两个屏幕使用一组布局。在这种情况下,维护/测试的工作量太大,您无法设计一种布局。

It should be possible to differ between WVGA854 and WVGA800 by using:

res/drawable-hdpi-long/
res/drawable-hdpi-notlong/

but i would definately recommend you to design the layouts so that it is robust enough to use one set of layouts for those two screens. It will be too much work to maintain/test of you can't design one layout in that case.

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