Folder name for 7\" hdpi tablet Android

2020-01-29 01:50发布

问题:

I have Tablet with 7" screen (600×1024) with hdpi (240 dpi classification).

I have created folder layout-sw600dp. But it's not working in this resolution tablet.

Its working fine with 7" screen (600×1024) with mdpi (160 dpi classification).

Which folder should I create for 7" (600×1024) tablet which has hdpi (240 dpi classification)?

回答1:

It depends from the Android API version you're building against, like mentioned here:

... However, this won't work well on pre-3.2 devices, because they don't recognize sw600dp as a size qualifier, so you still have to use the large qualifier as well. So, you should have a file named res/layout-large/main.xml which is identical to res/layout-sw600dp/main.xml. In the next section you'll see a technique that allows you to avoid duplicating the layout files this way.

You should also take a look here:

Preparing for Handsets

and

New Tools For Managing Screen Sizes



回答2:

In android, we use resolution in dp to measure the screen size, not resolution in px. Both of your two tablets have the same resolution in px, but their resolution in dp are quite different.

  1. 600 X 1024px with mdpi = 600 * 1024 dp

  2. 600 X 1024px with hdpi = 400 * 682 dp

You use sw600dp as the qualifier for tablet, which will effect the first device but not the second one.

In fact, the second device(400 * 682dp), is much more like a handset rather than a tablet, it should not use the layout for tablet.



回答3:

Make Your Layout like this:

res/layout/main_activity.xml           # For handsets (smaller than 600dp available width)
res/layout-sw600dp/main_activity.xml   # For 7” tablets (600dp wide and bigger)
res/layout-sw720dp/main_activity.xml   # For 10” tablets (720dp wide and bigger)

For TAB:

For example, if your application is only for tablet-style devices with a 600dp smallest available width:

<supports-screens
                  android:requiresSmallestWidthDp="600" />

I have Tablet with 7" screen (600×1024) with hdpi (240 dpi classification) which is comes under the Normal Screen see my screen shot.Its working fine with 7" screen (600×1024) with mdpi (160 dpi classification) which is comes under the large screen.

For Tablet .

MULTIPLE SCREENS:

For example, the following is a list of resource directories in an application that provides different layout designs for different screen sizes and different bitmap drawables for medium, high, and extra high density screens.

res/layout/my_layout.xml             // layout for normal screen size ("default")
res/layout-small/my_layout.xml       // layout for small screen size
res/layout-large/my_layout.xml       // layout for large screen size
res/layout-xlarge/my_layout.xml      // layout for extra large screen size
res/layout-xlarge-land/my_layout.xml // layout for extra large in landscape orientation

res/drawable-mdpi/my_icon.png        // bitmap for medium density
res/drawable-hdpi/my_icon.png        // bitmap for high density
res/drawable-xhdpi/my_icon.png       // bitmap for extra high density

Hope this will help you.