Minimum layout width (sw800dp) and various densities

How can I put different resources for different dpi in ICS with the same minimum sw800dp width?

Details: There are two tablets with ICS 4.0.4. The first has a resolution of 1280x800 and a density of mdpi (160). The second has a resolution of 1920x1200 and a density of hdpi (240). Thus, in terms of the smallest width, both of them have the same sw800dp specifier, but different mdpi / hdpi density qualifiers.

I need to have different layouts and images for these two resolutions.

So, I created two directories:

Layout-sw800dp-mdpi

Layout-sw800dp-HDI

I thought that each device would choose its own directory according to the smallest width and density. BUT they both take resources from the same sw800dp-hdpi folder!

I am very confused and do not know how to split the resources into two different permissions.

Any help is really appreciated. Thanks in advance.

+4
source share
2 answers

Use this to get density:

float density = getBaseContext().getResources().getDisplayMetrics().density; 

Screen height:

 int h = 0; Display display = ((WindowManager) getSystemService(WINDOW_SERVICE)).getDefaultDisplay(); h = (int) display.getHeight(); 

Screen width:

 int w = 0; Display display = ((WindowManager) getSystemService(WINDOW_SERVICE)).getDefaultDisplay(); w = (int) display.getWidth() 

After that, just select the right resources.

+1
source

You must use the same layout that is located in / layout / sw 800dp and create / drawable -mdpi, / drawable-hdpi to place your custom drawings, the system will apply the correct ones for each device using the same layout. These devices should have the same size and aspect ...

+1
source

Source: https://habr.com/ru/post/1432804/


All Articles