Background/UI for multiple devices - java

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.

Related

Android studio - Different device is using the same layout, but everything looks good only on one of them

I have 4 sets of layout xml and corresponding drawbles, including hdpi, tvdpi, xhdpi, and xxhdpi
I have 2 phones to test the app on, one is a virtual Nexus 5x, another one is a physical Galaxy Note 4
The xml layout works out perfectly on the Nexus 5x, but since (I assume) Note 4 has a smaller resolution / different ratio, the content is overlapping a little bit on it.
This app is very different than regular ones since it has a lot of image views in a relative layout arranged in a specific pattern. Problem is that the system is using xxhdpi resource and layout on both of the device. How do I fix it in a situation like this?
Thanks!
I faced the same problem few days ago.Use dimen.xml which is lacated under values folder.Make folder like values-sw600dp and make dimen.xml under this. Define all the relations in there and call it using #dimen/....
Android automatically will choose best match for your device.

Support all android screen size

I'm have tired to support all android , but I want to ask about supporting all screen size on android
I have 4 layout folders :
layout
layout-ldpi 2.7 inch = 240*320
layout-mdpi 3.2 = 320*480
layout-hdpi 3.7 = 480*800
layout-xhdpi 800*1280
layout-xxhdpi 5 inch 1080*1920
Is this setting in each layout support all devices or maybe I have missed some thing ?
Note : I have reviewed android site Android Developers many time .
I'm not sure what you want to achieve. You should split your resoures in two groups. One with density (folder called drawable) which contains images in different sizes for different display resolutions. The second one with layout (called layout) is for supporting different UI layout of each screen. Typically for tablet or mobile phones. So you should have forlder
drawable-ldpi, mdpi, etc. - here will be your png files
layout-"default",sw360, sw600, sw720 ("large" mobile, small 7" tablet, large 10" tablet). If your are targeting below 3.2, you can't you sw (smallest-width) but use older small, medium, large, xlarge screen size. - here will be your *.xml layout files
Don't mix up layout and density resource qualifiers together. See more here

Android drawable handling based on qualifiers

A friend asked me to help debug her app. The app provides drawables for many types of device configurations.
On Samsung Galaxy Mini, the app crashes, because it can't find any matching resources. (If all resources are copied to drawable folder, it fixes the problem.) I'm wondering about the reason of the crash.
The content of the res folder is as follows:
The only places where actual resources are stored are drawable-large-tvdpi and the drawable-normal-* folders. The rest of the folders contain only a test image for debug purposes (e.g. drawable-mdpi contains a picture with the text 'MDPI', so the app can use it to detect where the current device searches for resources). Obviously, the crash is not due to these debug images, but because the app can't find the actual resources referenced by the app's XML.
The Galaxy Mini has a "small" screen and an "ldpi" density. My guess is that since none of the folders that contain actual resources are for "small" screen size (they either have the "normal" or "large" qualifier), Android will not find any matching resource. (Remember that not all folders store the actual resources.) How should I reorganize everything to ensure that the app doesn't crash on any device at all?
(Note that I certainly read the relevant official Android doc.)
Okay, this gets a little confusing, but the issue is (kind of) articulated in the docs. Specifically:
Screen pixel density is the one qualifier that is not eliminated due
to a contradiction. Even though the screen density of the device is
hdpi, drawable-port-ldpi/ is not eliminated because every screen
density is considered to be a match [at first].
and
When selecting resources based on the screen size qualifiers, the
system will use resources designed for a screen smaller than the
current screen if there are no resources that better match (for
example, a large-size screen will use normal-size screen resources if
necessary). However, if the only available resources are larger than
the current screen, the system will not use them and your application
will crash if no other resources match the device configuration (for
example, if all layout resources are tagged with the xlarge qualifier,
but the device is a normal-size screen).
So, the issue is that you are providing density specific resources for normal/large screen qualifiers (e.g. drawable-normal-ldpi), but none for small (drawable-small-ldpi).

Issues on Android Screen Sizes

I am still trying to figure out a solution for this. Ive created a multiple layout on my res folder namely: layout, layout-sw480dp, layout-sw600dp, layout-sw720dp. Now testing it to real device which is (Samsung galaxy (7 inches) and Alcatel T10(7 inches)) they both go to layout-sw600dp but samsung seems much bigger than alcatel. Most of 7 inches tablet works fine except Samsung. Ive read this link Screen sizes and found out that
The original Samsung Galaxy Tab is an interesting case. Physically it is a 1024x600 7” screen and thus classified as “large”. However the device configures its screen as hdpi, which means after applying the appropriate ⅔ scaling factor the actual space on the screen is 682dp x 400dp. This actually moves it out of the “large” bucket and into a “normal” screen size. The Tab actually reports that it is “large”; this was a mistake in the framework’s computation of the size for that device that we made. Today no devices should ship like this.
My Samsung galaxy is 3.2 so I am sure that it fits on my requirements.
Does someone know how to handle this kind of problem?Like can I create a new folder for Samsung Galaxy only?
Sorry for my english, it is not my native language.
I struggled with the above issue for sometime and found that thr was no alternative for this in xml.
You must handle this during run-time, if you only want it for this specific model then u can get the model make during runtime here and then handle the scenario.
I dont see anyway u can have a special folder for samsung, if you find out,please do let me know :)

UI for Android - What resolution to design for?

I'd like my app to work on phones (320x480 usually) and tablets (840x600, 800x600 and 1024x600).
I'm not sure which resolution to design for and how it would scale on various devices. Can anyone please suggest what resolution and dpi should I use?
Discussing this with Tim Bray in a conference he said:
You should design for the biggest resolution and the higher dpi and then scale to the smaller ones.
Right now I think that tablet version requieres a different layout with different UX. For instance I would try using Fragments on the tablet version of my app.
Have a look at this resource:
Supporting Multiple Screens
Android handles different screen resolutions automatically in that you specify sizes in "dip" (device independent pixels) and by providing different drawable folders (drawable-hdpi, drawable-mdpi, drawable-ldpi) where drawables are fetched depending on the resolution capabilities of the device your app is running on.
If you want to target tablets specifically, then I'd start coding for the Honeycomb system. Devices will be available soon ;) The SDK is already available on the developer.android.com site.
Recently i developed a android app its in the market by name Starrpartners in this i use the design of 320x480 as a target and putting the images in mdpi folder. it worked pretty well on higher resolution as well .
You can check it by making your app and running it on different resolution simulator .
Hope it helps :)

Categories

Resources