My app has one layout for smartphone and one for tablets.
I want to use the same layout for both large and xlarge devices.
I want to support devices that use API 10 and up, so using sw<N>dp is out of the question.
How can I do that without putting the same xml file in both folders. I don't want to make code duplication. That's against any decent programming principles. :)
I think that a xlarge device would use a "large" resource if there's no xlarge option in the application.
http://developer.android.com/guide/topics/resources/providing-resources.html#BestMatch
So you can use only one XML to support either large or xlarge devices.
Related
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 am developing an Android application in portrait view only. This is working fine for 320 * 480 resolutions in all android versions (Version 2.2 to 4.2).
Now I want to support this application for the following resolution too:
960x540
480x800
1280x720
What will be the best approach to support my application for multiple screens.
I have 3 types of images: 1x, 1.5x and 2x.
In 320 * 480 resolutions I am using 1x images.
I searched a lot but still not clear what approach will be the best and right approach.
I have few options:
Use a single layout (under res/layout) and separate drawables (under res/drawable-mdpi, res/drawable-hdpi and res/drawable-xhdpi) for each resolution.
Using separate layouts (under res/layout, res/layout-large and res/layout-xlarge) and separate drawables (under res/drawable-mdpi, res/drawable-hdpi and res/drawable-xhdpi.) for each resolution.
Or any other best approach which should be always used whenever support multiple screens.
Onr more problem: When I am using any one above approach, my changes are not appear on hdpi and xhdpi screens.
Please guide me. Thanks in advance.
There is no single right way, I believe this decision depends of your application.
In apps with clean layouts, I make an unique xml_layout, and I use android:layout_weight to distribute the elements on the screen. Thereby, I get a similar distribution of this elements on the space available, in the all different screen resolutions.
Otherwise, when the layout is more complex, it's necessary to create different layouts to support the different screens.
The best option is 2, and it is the Android standard, recommended way of providing resources.
And I think your problem is due to you did not specify the correct type. For layout alternatives, you can also use:
layout-h720dp
layout-land
layout-sw600dp
layout-sw600dp-land
layout-sw720dp
layout-w720dp
Please refer to http://developer.android.com/guide/topics/resources/providing-resources.html#AlternativeResources
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