steveh
steveh

Reputation: 1372

Android layout on high density displays

i just released my app on android and have problems with customers with high density displays.

i added a debug thing to see what's going in, here is one sample output

Device: Nexus 10 Android version: 4.2.2 DisplayMetrics{density=2.0, width=2560, height=1504, scaledDensity=2.0, xdpi=298.275, ydpi=298.823} MainView w=1900 h=1342 mDrumKitMode=BIG KitView w=640 h=1266 x=1920.0 y=0.0

the main view is the music notation area on the left of the screen shot, its 1900 wide (MainView w=1900 h=1342) the drum kit is a bitmap that is 640w and 640 high. somehow, the display is scaling it to be full height of the parent, (KitView w=640 h=1266 x=1920.0 y=0.0). this doesn't happen on displays where density=1.0.

i have no way to test this since i can't get the emulator work on big displays for some reason and i don't have a high density tablet.

does anyone have an idea what could be going on? thanks

enter image description here

and here's another customer with a similar problem

Device: A700 Android version: 4.1.1 DisplayMetrics{density=1.5, width=1920, height=1128, scaledDensity=1.5, xdpi=224.73732, ydpi=224.11765} MainView w=1260 h=1044 mDrumKitMode=BIG KitView w=640 h=968 x=1280.0 y=0.0

i think its the scaledDensity=1.5 parameter, maybe i need to do something to disable automatic image scaling, i.e. set scaledDensity=1?

i should add that the entire application is based on exact pixel positions, both for the music notation display and the drum kit display which overlays images on top of the base drum kit image (you can see the drum pedals are in the wrong place on this image too). i don't want automatic scaling as i handle scaling inside the app for different display sizes and user preferences.

i should also add that all my drum kit images are in drawable-mdpi and all the other dpis are empty. this is because i scale images programmatically based on screen size and user preference BUT i think maybe the problem is a need to put some images in xhdpi? i guess i can do that but it will be a lot of work.

PS, i guess i found my answer here http://developer.android.com/guide/practices/screens_support.html

Provide different bitmap drawables for different screen densities

By default, Android scales your bitmap drawables (.png, .jpg, and .gif files) and Nine-Patch drawables (.9.png files) so that they render at the appropriate physical size on each device. For example, if your application provides bitmap drawables only for the baseline, medium screen density (mdpi), then the system scales them up when on a high-density screen, and scales them down when on a low-density screen. This scaling can cause artifacts in the bitmaps. To ensure your bitmaps look their best, you should include alternative versions at different resolutions for different screen densities.

i wonder if simply copying all the -mdpi images to -xhdpi will work?

Upvotes: 0

Views: 795

Answers (1)

Yevgeny Simkin
Yevgeny Simkin

Reputation: 28379

If you intend for this app to be used across devices you have no choice but to put in images for all the various density folders that exist (xhdpi,xxhdpi, hdpi, mdpi). It's also worth considering that you may want to change the actual layouts you include, to offer different ones for different devices.

Consult the documentation for how to handle this. http://developer.android.com/guide/practices/screens_support.html

If that creates an apk that's too heavy (I have no idea how many images you have) then you can go the other way and specify a no scaling drawable folder which will just use the images in their native density across devices. It's definitely wrong to use ONLY mdpi unless you intend to support only mdpi devices.

Upvotes: 1

Related Questions