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

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?

Answers


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


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.


Need Your Help

Karma vs Chutzpah

angularjs unit-testing jasmine karma-runner chutzpah

I have been trying to figure out what is the best way to write/run automated jasmine tests in visual studio. Currently, I am using jasmine with Resharper (using PhantomJS) and the test can be run f...