I've been developing for about 5 years and have always used 'dpi' folders in my res directory (mdpi, hdpi, xhdpi, etc) with 'sw' folders for tablets (sw600dp, sw720dp, etc).
I've noticed in Android Studio that, starting with the Nexus 6, google lists its newer devices in sw buckets rather than in dpi buckets.
I know we can still use dpi folders but SHOULD we? Or should we be transitioning to sw folders for all device sizes?
Or does it not matter?
google lists its newer devices in sw buckets rather than in dpi buckets.
First, those are independent concepts:
sw is "smallest width" and refers to size
dpi is "dots per inch" and refers to screen density
Also, there is no occurrence of "sw" in that screenshot that I can see. So, I do not know what is worrying you.
One guess is that you are looking at values like 420dpi and xhdpi and thinking that they are different concepts. They are both densities. The Android Studio UI is listing finer-grained density buckets than we use for our resources. xhdpi is 320dpi, for example.
Another guess is that you are looking at values like 420dpi and thinking that means -sw420dp, which is not the case.
I know we can still use dpi folders but SHOULD we?
For bitmaps, yes. For anything else, no.
Or should we be transitioning to sw folders for all device sizes?
Using size-based folders — -wNNNdp, -hNNNdp, or -swNNNdp for varying values of NNN — may be necessary depending on your UI. If you need different layouts or margins or padding or something based on screen size, those folders are useful.
Related
I am researching best practices for working with layouts in Android projects.
In the Android documentation says that from Android 3.2 to create qualifiers type -mdpi -hdpi etc is obsolete and that the best way is to create specific folders for each screen as sw600dp and etc. Also talks to create different layouts for each case, but how are the dimensions and images in this approach?
I create separate layouts for each case with fixed dimensions in the layout itself? How is that?
Images continue in folders like "dawable-mdpi"?
I spent some time studying the documentation but doubt continues ..
https://developer.android.com/guide/practices/screens_support.html
Correct me if I am wrong.
Before Android 3.0 drawable were placed in folders depending on the screen size. For supporting larger devices, putting drawable according to screen density was introduced. With this drawable were chosen depending on the pixel density of the screen and not just the size of the screen.
You can read about it in "How to Support Multiple Screens" section of this page https://developer.android.com/guide/practices/screens_support.html#support
So I think using small, normal, large, and xlarge is depreciated and we now use ldpi (low), mdpi (medium), hdpi (high), xhdpi extra-high), xxhdpi (extra-extra-high), and xxxhdpi (extra-extra-extra-high)
And sw600dp, sw720dp etc are for devices with screen dimension at least 600dp, 720dp etc. You can read more about it here: https://developer.android.com/guide/practices/screens_support.html#DeclaringTabletLayouts
You'll find answers to all your question in the documentation you spent some time studying. Go through it again, and I am sure things will be a lot more clear to you.
I have to provide two different font sizes for two different types of devices. The first group are smaller devices (e.g. the Nexus S, or devices with around 480px height) and the second group are all other phones (e.g. Galaxy Nexus, Nexus 4, 5 and so on). I already supported tablets.
By now I created a values-sw320dp folder with a dimens.xml in it - for smaller devices to use, and there is also the default values folder with their dimens.xml in it, to support all other phones.
The problem is that the dimens.xml from the sw320dp folder is applied everywhere.
Am I supposed to create a values-sw340dp or values-sw360dp folder for those devices? What is the purpose of the dimens.xml in the default values folder if I am going to bucket devices by their smallest width? How does a device put itself in a density bucket, look for their closest sw-dp folder or what?
I know that this question has been asked a thousand times before, but I really could not google it out or find it on SO.
The Nexus S is a common hdpi device (240 dpi), with a resolution of 480x800 pixels.
Therefore, you can use the values-hdpi for storing that device's dimens .xml.
You might consider to support smaller devices such as mdpi or ldpi ones, as well.
And "not so smaller" devices too (i.e.: xhdpi and xxhdpi).
There are different types of qualifiers (IMHO), ones are responsible for density and the others are more about screen sizes, and there are some identifiers for tablets. It is not only having a single suffix like hdpi for folder, you can play with couple of them.
You can find more info on the Official website:
http://developer.android.com/guide/practices/screens_support.html
I'm developing an app that targets only Android Phones, not tablets. The app should work in portrait mode only. I have all the dimensions (for views and fonts) in a dimens.xml file in the values folder.
I want to adjust the appearance for some commonly used phones, for example
Galaxy S2: 240dpi, 480x800
Nexus 4: 320 dpi, 768x1184
Nexus 5: 480 dpi, 1080x1800
I want to specify some font size and view dimensions specifically for these targets. I've tried with a lot of different values folder names, for example:
values-sw240dp
values-sw480dp
values-sw320dp, and so on,
but the app uses always the same folder for the three devices (normally the 480dp folder).
It is possible to specify dimensions in a resource file targeted for these devices?
Thank you in advance!
PS: excuse my bad English.
Yes it is possible. Every single folder inside the /res/ folder works exactly the same regarding those filters (xhdpi, sw600dp, en, land, etc).
The problem on your case is that you did not specify the correct folders. And the correct folders depends on what is the parameter you're using to specify the different dimensions.
sw___dp is for "smallest width", meaning, the smallest width of the screen (in a 800x480 phone is the 480 side) is that amount of DPs.
to specify DPIs you probably want to use hdpi, xhdpi, xxhdpi. Which will fit into those 3 devices you mention.
If you really want to use sw___dp, you probably want to install THIS APP on the devices and it shows you the sizing in DP for each screen (alternatively, if you don't have the devices, you'll have to do some math.
here is a comprehensive documentation of all the qualifiers you can use for resource folders.
It seems the best you can do is to use the dpi classes, and actually, I think that it's more correct cause you are optimizing you resources for every device in that class instead of only a specific few leaving the others to unknown results.
Not for specific devices, but for device sizes, it is possible using value folders named like these (width-height):
values-w480dp-h800dp
The designer of our company wants me to give him the resolutions of Android tablets so he will start designing a new app.
I know there are a lot of different resolutions (listed here: Android Tablets computers).
I also know about the division of Android to the different dpi's (ldpi, mdpi, ...).
My questions :
What should I tell the designer? He obviously not supposed to make a version for each resolution. Besides, some of the resolutions listed in the link above are in the same dpi, so which one should I choose?
Considering the fact the app is going to run only on tablets, what are the dpi classes I should use? Only hdpi and xhdpi? Or should I still use all 4 classes and limit the <supports-screens> tag in the manifest?
Is there a resolution that represent each of the dpi classes that I
should stick to?
I've done some reading about 9-patch. What's the point of using it if I still need to deliver a version for each dpi??
Thanks in advance!
The questions contain so much information.
1 Try to read the article and the references in it.
http://www.androiduipatterns.com/2011/11/design-patterns-for-responsive-android.html
You could also have a look at the web site for android design.
http://developer.android.com/design/index.html
In one word, designing for android tablets is more like designing websites. You cannot just design for one resolution.
2 Considering you are developing for tablets, it's necessary to support mdpi and hdpi. If the apps could be installed on phones, maybe xhdpi is also needed. It's not very strict.
3 dpi(dots per inch) = pixels per inch. So dpi is like density, it do not have strict relationship with resolution. But there is still a sheet could help you, try to find it in the following page
http://developer.android.com/guide/practices/screens_support.html
4 9-patch resource is very useful. With which a small png could stretch to any size without distortion. And it could also help to reduce the size of your resources.
In most situation, you do not have to make 9-patch for each dpi, since it could stretch to any size you want. But if the 9-patch png contain some information itself, like min height and padding, it's necessary to make different versions.
Here is what I would do:
See what combinations you have. There are mostly 3 resolutions for tablets (1280x800, 1024x600, 800x480) and mostly 2 densities (hdpi and mdpi). That is at most 6 versions. Select a few matching your most logical targets (I would choose xlarge mdpi (9" 1280x800), large mdpi (7" 1024x600) and normal-hdpi (4-5" 800x480) and design on these.
Some graphical elements don't need to be designed for each combinations, like backgrounds, may be buttons… Here comes the 9-patch. To be put in drawable-nodpi folder. One resource fits all.
Do one version first on you major target, then see how it fits on the other targets, and consider adjustments from there.
Use ScrollViews if you don't want to position every item pixel-perfectly on each device.
i am attempting to get my android app to work on both phone type devices and tablets. for the layouts i have layout-normal and layout-large and i place my xml files inside each and it seems to select the correct one for each device (layout-normal for phones and layout-large for tablets).
however the problem arises for the drawable folders. i have drawable-hdpi, drawable-mdpi and drawable-ldpi. the tablet is taking its images from the drawable-mdpi, and the phone is taking its images from the drawable-hdpi. from the reading i have been doing this seems to be backwards??? this seems to happen on both the emulator and real devices, could i be doing something wrong? am i mixing something up?
Clayton,
drawable-hdpi and drawable-mdpi is not related to the size of the screen itself, but to the resolution of the display.
It's probably easy to think in terms of the iPhone 3GS and 4 for this (bear with me please). The 4 has retina display, hence a much higher resolution. Using the same sprites you'd use with the 3GS would result in a blurry display.
Android phones are, if anything, much more diverse in terms of screen options.
If you want to be able to aim different layouts at different resolutions, please try putting the layouts into /layout-xlarge, /layout-large, etc...
You can find more here:
http://developer.android.com/guide/practices/screens_support.html
There are some changes that you can see for Android 3.2 and above:
Beginning with Android 3.2 (API level 13), the above size groups are
deprecated and you should instead use the swdp configuration
qualifier to define the smallest available width required by your
layout resources. For example, if your multi-pane tablet layout
requires at least 600dp of screen width, you should place it in
layout-sw600dp/. Using the new techniques for declaring layout
resources is discussed further in the section about Declaring Tablet
Layouts for Android 3.2.
ldpi, mdpi, and hdpi refer to pixel density, not screen size.
The accepted answer does not address a serious problem: if you have many drawables, you end up with an unnecessarily big apk file because of resource duplicating. The only solution for that is the resource alias option described here:
http://blog.evendanan.net/2011/03/Android-resources-and-device-fragmentation
Edit: I just beheld that OP didn't realize that most phones have hdpi density, while most tablets have mdpi density. At the same time the tablets mostly have higher resolution. Hence Android will use smaller pictures for higher resolution.
You can overcome this only by using vector images or using the methods described in the accepted answer and in my answer.
drawable-hdpi - application use this drawable images when the device has high pixel density
drawable-mdpi - application use this drawable images when the device has medium pixel density
drawable-ldpi.-application use this drawable images when the device has low pixel density