Android does not access xhdpi folder for tablet view - android

I have both hdpi and xhdpi folders in my res folder. However, android makes use of hdpi xml file for 1280 X 800 resolution of a tablet. Could it be because my xml file accesses resources which are in drawable-hdpi folder but not in drawable-xhdpi folder?

I think you are confused with DPI vs screen sizes, which resolution along does not provide. You can have a XHDPI device with a small screen that is very high resolution (such as the Galaxy S3) or a MDPI or LDPI device with a very large screen (such as when you use Android on your TV).
Generally speaking, Dot per pixel = Resolution / Screen size.

Not all android devices are set to the right density by the manufacturer, its really a hodgepodge of densities no matter what resolution you think you have, the device could still be seen by the android OS as a lower or different density than you think
if the android OS thinks your device is HDPI then it will access HDPI drawables

Related

HDPI, LDPI, MDPI

Sorry. I have no idea about Android screen size HDPI, LDPI, MDPI. How can I check my flutter app in these screen size?
Create new android emulators with different pixel densities, and run the app on them. I wouldn't worry about ldpi (.1% of devices). The cutoffs are 160 dpi (mdpi), 240 dpi (hdpi), 320 dpi (xhdpi) and 480 (xxhdpi).
Generally this shouldn't be a problem as long as you specified all your sizes in dp rather than pixels. The most likely thing to want to change is images, make sure that any non-vector image looks good at multiple resolutions.
HDPI, LDPI, MDPI all refer to the pixel density of your display and not resolution of the device.
Generally when developing for multiple screen sizes you should focus more on viewport (say 360dp and 600dp as your breakpoints), then find or create new android virtual devices that match your viewport and then run your app on those devices.
Here are a few good links:
Material IO Pixel Density
Android Documentation
Android Device List

how to design tablet ui with high resolution but less density screens?

I want the emulator to make use of the files present in the xhdpi folder and at the same time it should have low density. My emulator is set to a resolution of 1280 X 800 similar to motorola xoom tablet. Now if i keep a density of 149 ppi, android does not access the xhdpi folder. Please help. TIA.
Do not misunderstand Screen size, Screen density and Resolution. Read this article first.

How mdpi, hdpi, xhdpi folder works?

Extract from Android Developer Guide link above:
320dp: a typical phone screen (240x320 ldpi, 320x480 mdpi, 480x800 hdpi, etc).
480dp: a tweener tablet like the Streak (480x800 mdpi).
600dp: a 7” tablet (600x1024 mdpi).
720dp: a 10” tablet (720x1280 mdpi, 800x1280 mdpi, etc)
So i got graphics(images) at resolution 320 pixels per inch from designer in these dimension only
480x800 hdpi
720x1280 mdpi
800x1280 mdpi
I am confused which size of images should be placed in mdpi folder, hdpi folder and xhdpi folder. I want to make one application which can work on most android phones and tablets ?
You can create different graphic objects for use at different pixel densities. Android treats mdpi (160 pixels/inch) as the base density. So for mdpi devices, 1 dp = 1 pixel. At higher densities, there are more pixels per inch (240 for hdpi, 320 for xhdpi). Android attempts to make graphic images occupy the same physical dimensions on the screen regardless of the device pixel density. So if all it finds is an mdpi resource, and the device is hdpi, it will scale the graphic by 240/160 = 150%, and it will double the size of the graphic for xhdpi.
If you don't want this automatic scaling (which can make graphics look poor), you can simply supply your own version of graphic resources for use at higher densities. These graphics should be of the same size that Android would scale an mdpi resource.
Note that the pixels/inch that was stored in the image file has nothing to do with this. It's all based on where you put the graphics files in the resources directory for your project. Any graphics placed in res/drawable are assumed to be properly sized for mdpi displays, as are graphics placed in res/drawable-mdpi. Image files that it finds in res/drawable-hdpi are assumed to be properly sized for hdpi displays, etc. When your program runs on a particular device, Android will first look for a graphic that matches the display density of that device. If it does not find one but instead finds one for a different density, it will use that and automatically scale the image based on the above rules.
When you request a resource for which you provide alternatives, Android selects which alternative resource to use at runtime, depending on the current device configuration. To demonstrate how Android selects an alternative resource, assume the following drawable directories each contain different versions of the same images:
drawable/
drawable-en/
drawable-fr-rCA/
drawable-en-port/
drawable-en-notouch-12key/
drawable-port-ldpi/
drawable-port-notouch-12key/
And assume the following is the device configuration:
Locale = en-GB
Screen orientation = port
Screen pixel density = hdpi
Touchscreen type = notouch
Primary text input method = 12key
By comparing the device configuration to the available alternative resources, Android selects drawables from drawable-en-port.
The system arrives at its decision for which resources to use with the following logic:
Ref : How Android Finds the Best-matching Resource
Other References : Density independence , Providing Alternative Resources and Best Practices
And I will say that you should read complete page Supporting Multiple Screens, I don't think nothing will be better documentation than it...
I'm confused myself with all the screen size fragmentation but the basics are:
1. You need to create various folders under layouts to work with your images
2. Images will exist in the drawables folders also under various folders.
3. You should have a basic /layout and /drawable folder to accompany non-specific folders
4. Work from xhdpi then scale images down!
Examples for specific screen folders:
/layout-hdpi
/layout-xhdpi
/drawable-hdpi
/drawable-xhdpi
From what I know:
480 x 800 is hdpi (older phones eg S2, HTC Desire etc)
720 x 1280 is xhdpi (new phones eg S3, Galaxy Nexus etc)
Basically, Depending on the phone, android will grab resources from the necessary folder and if there is none then it will grab from the main '\layout' or '\drawable' folder. For example, the app running on a Galaxy Nexus will grab resources from '\layout-xhdpi' if the folder exists.
yes, you can make one app, but was need creating folders: /res/drawable, /res/drawable-mdpi, /res/drawable-hdpi and add content for all screen sizes

Android Multiscreen Support issue

hi guys i have been developing android app that should match most of the screen resolutions. And i just got struck at setting the drawable folder for this two resolution
1. 480 x 800 with approximate density of 217
2. 540 x 960 with approximate density of 240
And i have a different set of images for both the resolutions and i have set hdpi for 540 x 960 but don't have an idea of going about the 480x800 which also falls under hdpi. After goggling found a drawable qualifier called tvdpi which supports the appr. density of 213
When i set the tvdpi qualifier to the drawable folder i get "invalid resource directory name" error
Resolution and dpi are not directly related. It just so happens that many 800x480 devices are HDPI, then can just as easily be low dpi though if the screen is big enough.
If you really need direct resolution matching you will need to target API level 13 and use available width and height qualifiers for your resources or if you need to target a lower API level than 13, create your own resource loading scheme.
You can also use a combination of density and size qualifiers but that still leaves some room for two different resolutions falling into the same bucket.
But before you pick, you need to ask yourself do you really want the same pixel size for your drawables on a 3.7" 480x800 screen as you do for a 7" 480x800 screen.

Android: Optimize for high-dpi devices only but still support (small- and) medium-dpi screens

I'm building a game with graphic assets in hdpi resolutions (hence I put the files in drawable-hdpi directory). I don't want to have a corresponding mdpi resolution of the images, and I will code everything in 240-dpi based pixel coordinates.
Is it possible to still allow mdpi and ldpi devices to run the app, by automatically scaling the graphics from the hdpi version?
If you put the graphic assets in drawable (with no qualifier) they will be used by all 1.6+ phones and scaled as appropriate for the screen resolution of the phone. You only need to use hdpi if you want to provide different assets for different screen densities.
You should put the assets in the drawable-hdpi/ directory. Phones will scale them down automatically with the following ratio:
3:4:6:8
l m h xh
So your hdpi assets would scaled 3:2 on a mdpi device. If you only put them in the drawable/ directory, the system uses mdpi as a baseline, and your assets will actually be scaled up on hdpi devices.
Note: If a density qualifier is not defined in a directory name, the system assumes that the resources in that directory are designed for the baseline medium density and will scale for other densities as appropriate.
How to Support Multiple Screens
How Android Finds the Best-matching Resource

Categories

Resources