How to differentiate layout for 480 * 800 and 480 * 854 screen resolutions in android?

蹲街弑〆低调 提交于 2019-12-06 05:15:15

问题


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?


回答1:


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..




回答2:


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.



来源:https://stackoverflow.com/questions/5499863/how-to-differentiate-layout-for-480-800-and-480-854-screen-resolutions-in-an

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!