简体   繁体   中英

Background/UI for multiple devices

I'm new to Android programming and I'm stuck with a very specific problem. I want my application to run on multiple screen sizes and densities.

I have several real devices with different screen resolutions (Samsung Galaxy S7 Edge [xxxhdpi], Samsung Galaxy A5(6) [xxhdpi], Samsung Galaxy Note 10.1 tablet [xhdpi].

I made one background and scaled it down for every generalized density. I saved the files as “background.png” in separate folders like suggested in Supporting Multiple Screens .

After testing the APK on the devices, everything worked fine except the background on the S7. It will always load the next lower resolution bitmap (xxhdpi instead of xxxhdpi). I looked countless threads how to fix this problem but nothing worked so far.

The resolutions of my bitmaps are:

drawable-mdpi        //320x480
drawable-hdpi        //480x800
drawable-xhdpi       //720x1280
drawable-xxhdpi      //1080X1920
drawable-xxxhdpi     //1440X2560

I hope that someone can help me on this one. I'm really losing my mind.

This is a little complex but I'll try to keep it simple. The android system chooses the right resources based on a lot of factors (which you can see when you create a new resource file under the "Available qualifiers" list) which you can group to create a resource shared by different configurations or use only one of them to specify one particular configuration. But you cannot control witch resource the device will use for the most part (there are some you can specify yourself ex: night mode). Your S7 probably uses the wrong resource because probably one of the settings for the display resolution is set at a lower setting (ex: battery saving modes lower resolution, gaming mode.. etc, accessibility settings). And if you want a tablet to use a different drawable then a phone then you should use the "smallest screen width" qualifier since you can specify different screen sizes in Dip(ex: sw320dp is a normal phone, sw440dp is a big pixel phone, sw720dp is a medium tablet and sw1048dp is a bigger tablet). Read more here

I'm also facing like this. My app only works on high resolution mobile only. Then I found that error. I placed my drawable on drawable-hdpi only . For every assets we have to place default drawable in drawable folder

put default drawable in that folder. drawable

For handling images on the s7 device we can give height and width to the image view. Set the values for height and width from the dimens file. For handling s7 UI need to add the dimens-sw411 file and specify the height and width in that.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM