I have made one app which is working fine for both Tablets and Phones. But as we know we should have a different layout for tablets( such as bigger font and images etc).
My question is how to provide the layouts such that they are only picked by tablets and not phones.
Example: If i provide xhdpi or hdpi layout thinking of these as tablet then it may be picked by some device also which is using this same configuration.
So how to be sure that a current device is tablet or phone and provide a specific layout for it?
My question is how to provide the layouts such that they are only picked by tablets and not phones.
Either use the classic screen size buckets (e.g., res/layout-large/) or come up with your own buckets using -swNNNdp (e.g., res/layout-sw600dp/ for resources to be used on devices whose shortest width is 600dp or higher).
This is explained in the documentation here, here, here, and perhaps a few other spots as well.
Example: If i provide xhdpi or hdpi layout thinking of these as tablet then it may be picked by some device also which is using this same configuration.
-xhdpi and -hdpi are screen densities and have nothing directly to do with screen size.
Related
I'm writing an Android app and have read up everything I can find on fragmentation and handling multiple screens, particularly from the official Android documentation.
I understand different screen densities utilize the various folders (mdpi, hdpi etc.) for images of varying sizes, and different screen sizes can utilize different layouts by defining them in res/layout-sw600dp layout-sw720dp etc. which all makes sense.
However, when developing my app my primary test device was a HTC Desire X phone 400x800 with 240dpi density and all looks well. I then tested it on a Prestigio Multipad 8.0 tablet and this is where I'm getting confused. The tablet has a screen size of 786x1232 BUT the screen density is only 160dpi. Owing to the fact that the screen density on the tablet is smaller, Android therefore uses the images in the mdpi folder for the tablet, and the slightly bigger ones in the hdpi folder for the phone! This therefore results in images way too small on the tablet.
I don't need to edit the layout for the tablet so the sw720dpi folders aren't a help.
What am I missing or not understanding properly here? How can I make my images scale up for the bigger, lower density tablet screen?
OK, I figured this out eventually. My mistake was I didn't realize drawables work exactly the same as layouts in that I could have a drawable-sw720dp folder which Android fetches the images from in the case of a screen with at least 720pixels of width. For completeness in the scenario I described I could have a drawable-sw720dp-mdpi folder in which to store my images.
I had an additional issue then whereby I had 2 copies of the same image in different drawable folders but I discovered you can reference images using an alias just like layouts. Details of how to do that can be found here.
I made an extra layout for the S3 (rebel of all layouts) and people said, using a layout-sw320dp is good for the s3. Everything worked, the s3 chose this folder and the layout looks great on the s3.
But when I try to run my app on a 10" tablet, the tablet uses the same folder like the s3 which is totally wrong.
How can I make the sw320dp layout visible only to the s3 or at least how can I make 10" tablets use the xhdpi folders? I already read, that the android system thinks, because sw360 is a "new" type, it's the best. But I don't know how I can avoid that..
Thanks
This is because of higher order of precedence of sw<???>dp qualifier in Android. res-sw<???>dp has got the 2nd highest precedence in the order of qualifiers.
See Configuration qualifier Table. This is the default order in which Android takes the directories in resource folders. So basically whatever folder you provide which have lower precedence, Android wolud not take that. See How Android Finds the Best-matching Resource.
Here sw320dp means devices with at least 320dp of shortest width. Both S3 and 10" tablets come under that. So Android always take that folder for devices which have shortest width of 320dp.
These are some alternatives you can do:
Make layouts like drawable-720dp(10") and drawable-600dp(7") for
tablets. The problem with giving sw<???>dp is that it's been introduced only in API 13 only. So tablets with API < 13. can't use that.
Change the layout for high density phones to layouts with lower
precedence values.
I basically support this method. This way you can give more support
to lower API devices.
Okay i am familiar with this site and what it says
http://developer.android.com/guide/practices/screens_support.html
But im still having a problem.
I am designing layouts for phones and tablets from gingerbread to jelly bean.
I had started with a basic layout folder and designed everything for a galaxy nexus phone. now im going back and adding tablets. one question here is should i use layout-xlarge/layout-large or layout-sw600dp/layout-sw720dp? im guessing the smallest width is what i should be using.
But thats not the issue.
This issue is im trying to do that layous for Galaxy Nexus (720x1280) and Nexus S (480x800) These are much different yet eclipse doesn't seem to let me differentiate.
So i just want to be clear on what i should be doing to do this right. is this what i should have to cover the devices i want to?
layout-hdpi
layout-xhdpi
layout-sw600dp (instead of layout-large)
layout-sw720dp (instead of layout-xlarge)
will doing those layout-hdpi and layout-xhdpi separate the layouts for a Nexus S and Galaxy Nexus?
First, the layout-sw are based on dp, Density-independent pixels, rather than pixels. You can think of dp as 'actual size' pixels i.e., 1dp is the same physical size no matter what device is being used.
Therefore the Galaxy Nexus, which has a 720x1280 pixel screen is only 360x640 dp resolution and there is no overlap between a phone and the higher sw600+ folders.
The large/xlarge buckets will continue to work on all tablets, but if you need finer grained support or alright only using tablet layouts on Android 3.2+ devices, then you only need the sw--dp folders. You can also use both without copy/pasting your XML by using a reference file, as detailed in the below blog post.
More details on how to support multiple screens can be found in Supporting Multiple Screens guide and some of the reasoning behind why you'd want to use the new sw---dp buckets can be found on the Android Developers blog post announcing the feature.
Just use layout-large and layout-xlarge. When you're developing the layouts and want to know what it looks like on a certain device, just change the view and it will pull the appropriate XML from the correct folder.
I have created layout files for small, large and xlarge screens sizes, but when I load my app on a Samsung S3 emulator, with the resolution of 720 x 1280 it is still the default layouts which are being used.
I do not understand why android is not using my specific layout files.
I have placed the layout files in the folders layout-large, layout-small, layout-xlarge under the folder layout.
Hope someone can point me to what I am doing wrong.
Thanks.
The screen size buckets you are referring to are deprecated since Android 3.2 (API level 13?). If you are targeting later versions of Android then you should be using the "smallest width" qualifier to enable a finer grain control.
The Samsung Note for example will leverage the old "layout-large" bucket but it doesn't respond well to mini- or normal tablet layouts. These devices are normally running Android post 3.2 (the DELL Streak and original Galaxy 10.1 tab are the exception). To differentiate in this instance supply a layout-sw520-port and layout-sw520-land resource folder and place the layouts here. Further differentiations can be made for Nexus7 type devices (sw600) and so on. Note there are reserved pixels on screen (notification/action bar etc) so the physical smallest width DPI is not precisely what your layout will respond to (albeit predictable close).
Diana Hackborn (hackbod) wrote a comprehensive blog post on the subject describing the motivation s behind the change and the sorts of problems (cf. Your issue) it solves. Google have also put together some advice on designing for multiple configurations as part of their tablet drive. Have an Android Dev Guide trawl should you hit further issues.
Samsung S3 is in the "normal" category.
What I found helped me greatly to get layouts which scales to different resolutions was layout_weight="1" and layout_width="0dp", just in case someone drops by this question wondering why there layouts do not scale in some areas.
I am developing app for Mobiles(HTC) and Motorola Xoom. But the problem i am facing is that both Uses Drawable-mpdi bitmaps.
abd there is difference in screen size of both, The Image which is perfect on Mobile is became very small on Tablet.
I have checked the list for Drawable folders used by devices.
Please Help me how to sort out this Problem ?
How can I make different size images for both of devices.
Thanks
I can think of a couple of ways to do this. Hopefully, other people will add more.
You could use the MDPI folder with a single image of high enough resolution for the tablet then let Android scale it for smaller devices using the scale properties of an ImageView. However, you are focusing only on HTC and Xoom and that doesn't solve your problem for devices which use other generic resolutions.
Or, you could use the drawable-nodpi folder and have several images with your own resolution naming scheme e.g. myimagesmall.bmp, myimagemedium.bmp etc. Then at runtime, measure the device screen size and DPI and load the appropriate image.
Or, combine them. Use nodpi and a single image and let Android scale for you. Using BitmapFactory, you can control dithering and anti-aliasing to get good results.
Good luck!
Speaking about density, Motorola XOOM also uses mdpi drawables, so to differenciate drawables between tablets and small phones you should use folders with respect to screen sizes. Phone screen size is usually treated as normal, and a 10-inch tablet is xlarge, so drawable-xlarge-mdpi is the folder name you should use to place drawables for 10-inch tablets. Hope this helps.
From the http://developer.android.com/guide/practices/screens_support.html
The configuration qualifiers you can use to provide size-specific resources are small, normal, large, and xlarge. For example, layouts for an extra large screen should go in layout-xlarge/.
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