I know how to use the following folders but for example I do not know what is difference between layout-small and layout-sw320dp?
Also, Suggest for me that which the folders are important to optimization.I do not like my program be seen for users as irregular.I want a final answer from you.
Based on which the folders I design my layouts? Because I have not multiple android devices to test the layout in different screen size.
I know how to use the folders and I have not problem about it.but my question is which the folders for continuous use and for all devices?
layout-sw320dp
layout-sw480dp
layout-sw600dp
layout-sw720dp
layout-small,
layout-large etc...
Both are qualifiers to define layouts for specific screen sizes.
Before Honeycomb - 3.0 (I guess), the screen's diagonal size was measured based in 4 groups: small, normal, large, and extra-large.
After that layout resources are defined for screen sizes with the smallest width (sw stands for smallest width).
Resuming, layout-small is deprecated and layout-swXXXdp qualifier should be used instead.
You can get more info about these qualifiers in Supporting Multiple Screen's Android official doc page.
The difference is that the qualifiers -small, -normal, -large had been marked as deprecated in API 13. Now the recommended way to go is using the -swdp folder structure. (see http://developer.android.com/guide/practices/screens_support.html#support )
The number of resources folders in your project depends basically on the type of devices you're targeting at (small phones, phablets, tablets, ...) and the number of different layouts you want to maintain. In most cases implementing a layout for landscape/portrait modes for phones and for tablets should be enough. Though you can create another layout for a specific screen size if you really need it.
Hope this helps.
Related
I am going to develop new application in Android. This application should only work in portrait (even for tablet). Also the UI and layout design should be similar on phones and tablet. We can't change the layout design for tablet as it has huge area to use. We have to stretch all the images to match phones. We can use nine patch. But I am little bit confused of using images in multiple drawables.
As per my analysis (may be wrong.. : ) ) the screens are divided into density and sizes. We can use the scaling ratio of 3:4:6:8. But this ratio is based on the density. But in my case I have to stretch the entire UI to fill the Tablet screen.
So what are the drawables that can be used for a app like this which can support multiple devices. And what are the screen sizes for which we have to design.
And this application needs nearly 100 layouts. So I am planning to maintain single layout and designing the layout using weight for each layout instead of using dimension.
Also if I used multiple APKs to support different screen size what are the drawables used to support
1. Small and Normal
2. Large
3. Xlarge
I just did something very similar. To stretch the app without creating new layouts I used dimensions set in XML
res/values/dimensions.xml
res/values-sw600dp/dimensions.xml -> 7+ inches
res/values-sw720dp/dimensions.xml -> 10+ inches
Dimensions are resources files:
<dimen name="default_padding">11dp</dimen>
You can increase the dimensions by about 30% in the 600 and 720 file.
Then simply used #dimen/default_padding in your layout and it will be scaled
Regarding images, either you make sure you have all your assets in all densities, or you set fixed size to you ImageView's and appropriate scaleType
Firstly, you do NOT want to create multiple APKs to support multiple screen densities. Android provides all of the framework you need to support everything within one build, you just need to create the right resource hierarchy drawables with your desired densities.
So what exactly do you need... based on your question the following:
portrait mode: you can specify this in each Activity declared in your AndroidManifest file using the following:
<activity android:name=".MainActivity"
android:label="#string/app_name"
android:configChanges="orientation" >
...
</activity>
NOTE: Per the Android docs, if you're targeting API >= 13, and you use the android:configChanges attribute you should also use the android:screenSize attribute to help specify size changes.
dimension sizes for various screens: as touched upon, this can also be handled in resources. This is your best way to use one common layout file but configure the layout for use on numerous devices. See http://developer.android.com/guide/topics/resources/more-resources.html#Dimension for how to use dimensions if you're unfamiliar
drawables: it sounds like this is the crux of your question. As you mentioned, using nine-patches will help you reduce your app footprint and fill in extra space (see here and here for more on nine-patches). The sizes you should support and the densities needed for those sizes are discussed in great detail in Android design docs, so much detail I could not even do it justice rehashing it here. I've provided links below to as many places as I could remember that this is discussed.
Good luck!
Here are links to Android design docs that you will find useful (some of which have been mentioned):
http://developer.android.com/guide/topics/resources/providing-resources.html#AlternativeResources
http://developer.android.com/training/multiscreen/index.html
http://developer.android.com/guide/practices/screens_support.html
http://developer.android.com/design/style/devices-displays.html
In addition to the pixel density specific folders, you can specify screen-size specific folders
drawable/
drawable-large/
drawable-xlarge/
drawable-hdpi/
drawable-large-hdpi/
drawable-xlarge-hdpi/
drawable-xhdpi/
drawable-large-xhdpi/
drawable-xlarge-xhdpi/
So you could design scale appropriate graphics for the various screen sizes and densities. Please note that a give screen size category (e.g. "large") will only give you a rough idea as to the actual device pixel dimensions of the device, but you'll get good guidelines for min/max dp ranges.
For example, you might have a 100x100 image you want to display on phones (screen size "normal"), you'd create image assets at 100x100, 150x150, 200x200 for drawable, drawable-hdpi, drawable-xhdpi folders respectively. But on 7" tablets, i.e. "large" screen size devices, you might display this same image at 200x200, so your "drawable-large" folder assets would be 200x200, 300x300, 400x400, and on 10" tablets, i.e. "xlarge" screens, you might display the same image at 300x300, 450x450, 600x600, so these go in "drawable-xlarge-*" folders.
All the details are here:
http://developer.android.com/guide/practices/screens_support.html
First you need all the possible screen layouts
drawable
drawable-ldpi
drawable-mdpi
drawable-hdpi
drawable-xhdpi
drawable-xxhdpi // phones like s4
drawable-xlarge
drawable-tvdpi // nexus 7 etc
drawable-xlarge-xhdpi //tablet like nexus 10
layout : for phone
layout-sw600dp
layout-sw720dp
then you need to put all use 9- patch images for buttons etc ... you can also make your custom drawable it would be easy and handy to work on ..Also you can take dpi for each screen by using switch and scale it the layout accordingly.
As, in one of my project I had used this technique for showing respective thing to each resolution device .
DisplayMetrics metrics = getResources().getDisplayMetrics();
int densityDpi = (int) metrics.density ;
switch (densityDpi) {
case (int) 1.5:
break;
case (int) 2: //1.75 will be 2 in INT.
break;
default:
break;
}
also keep all the values you are going to used for margin padding etc values-sw600dp for tvdpi tablet ,value-sw720dp for tablets
Last but not least keep all thing generic as much as you can and put it in drawable ..
I have seen some ppl who used background patterns of different dpi's and put it in respective drawable .. if there is such thing like pattern make your custom drawble and repeat it accordingly
that will save your time .. hope it may help you
In order to stretch all the images to match phones you can specify the image size using the sdp size unit. This size unit is relative to the screen size so it can fulfill your requirement.
I am making android application in tablet using fragments so that I arranged 8 buttons vertically in 10.1 tablet it is showing fine but in 7.1 tablet only 5 icons it is showing.
So How can I manage height and width properly in all tablets ... please help
Remember to write different xml layouts (with same name) and place to different folders: layout-large, layout-normal, layout-small and layout-xlarge. Same is with drawables (different size images) and values (different type padding and other values). These folders are for different phone/tablet types with various resolution and screen size. If you do it, then you can easily manage layout for small device and not touch big screen devices. Device is picking xml file automatically so it's good practice to place xml files in different folders for various phones.
More information you can find in http://developer.android.com/guide/practices/screens_support.html
You can use different layout for different screen sizes. You can also add different buttons and other drawable also. Please see the link
Supporting Multiple Screens
You can write different xml layouts using different folders:
For example:
res/layout
res/layout-sw600dp //used by 7''
res/layout-sw720dp //used by 10''
Also you can use the same layout with the same component but with different dimensions.
You can use #dimen/my_dimen notation, and then put your my_dimen in different folders like:
res/values/dimens.xml
res/values-sw600dp/dimens.xml
and so on..
Official doc: http://developer.android.com/guide/practices/screens_support.html
I'm implementing an application and I want to support all screen sizes. I have 4 layout folders: layout, layout-small, layout-large and layout-xlarge.
Which screen size supports the standard layout folder? Is it even necessary?
Which screen size supports the standard layout folder?
In your case, it will depend on what files are in what directories.
Let's say that you have main.xml in layout/, and not in any of the other three candidates. Then, setContentView(R.layout.main) will use the copy in layout/.
Now, let's say that you add a revised version of main.xml in layout-xlarge/. On an -xlarge device, Android will use the layout-xlarge/ version of main.xml, and on other screen sizes, Android will use the layout/ version of main.xml.
Now, let's say that you add a third main.xml version, this time in layout-small/. Android will still use the layout-xlarge/ copy of main.xml for -xlarge devices. However, all other devices will use layout-small/, and the layout/ copy of main.xml will be ignored. Android will not try to shrink a layout from a larger size (e.g., -xlarge layout on a -normal device), but it will try to expand a layout from a smaller size (e.g., a -small layout on a -normal device).
What I tend to do is use layout/ for:
Layouts that do not need different versions for different sizes
Layouts to be used on -normal devices (as I rarely support -small)
I then use layout-large/, layout-xlarge/, or their Android 3.1+ replacements (e.g., layout-w720dp/) for layouts to be used on larger screen sizes.
However, that is just my particular style, and you are welcome to do what you want, within the usage rules described above.
using modern notation is a better solution:
/layout // for phones
/layout-sw600dp // for 7 inch tablets
/layout-sw720dp // for 10 inch tablets
In popular:
Mdpi screen smartphone is cheap
Hdpi screen smartphone is expensive.
If you use layouts only mdpi folder, this layout will be used for all screens
Legend:
layout-small = ldpi
layout = mdpi
layout-large = hdpi
layout-xlarge = xhdpi
For quite a long time, I have been declaring resource folders for 4 different densities:
drawable-ldpi
drawable-mdpi
drawable-hdpi
drawable-xhdpi
In the layout's XML, I have been using fixed widths (while still density-independent) such as 128dp for those graphics.
However, when more and more large-screen phones, and especially tablets, were introduced, that approach did not work anymore. Although you provide density-independent resources this way, the layout will not look good on large screens.
This is why I think I need to add Dimension resources that depend on the screen size, for use in the XML layouts, e.g.:
values
values-w600dp
values-w720dp
values-w1024dp
But does that mean that I should drop supporting those 4 density containers? Or do I need to provide 16 resource folders, i.e. one for every combination of density and size?
I can't find any good help in the Android documentation as to this topic.
drawables and layouts are different. To answer your question, should you stop support those densities. Yes, but you should still support xdpi and hdpi. Romain Guy recently said that modern devices like the Nexus 7 (at a tvpi) can scale the assets properly enough that mdpi isn't really needed. And nobody uses ldpi anymore. Last I looked is was less than 2% of the market.
About layouts. A Nexus 7 (1280x800 tvdpi) would use something from the values-w1024dp but still get assets from the drawable-hdpi folder. Those two aren't mutually exclusive. Something like a S3 would also pull from the values-w1024dp but use drawable-xdpi. You only need to provide an alternative layout if your use-case calls for it.
So do you need 16 different things? No. You do need xdpi & hdpi (if not mdpi). You may want to include alternative layouts for different sizes. You can be as specific as you want or as generic. Unless you're doing a hybrid app for both phone & tablet (7 & 10 in) you probably don't need a lot of xxxx-sizexxx folders.
In the layout's XML, I have been using fixed widths (while still density-independent) such as 128dp for those graphics.
This is probably a source of your issues. Your layouts should be as fluid as possible using wrap_content and match_parent. Fixed sizes should be reserved for padding around the sides and image where you know the size ahead of time. If you do this, your layout should look decent at any size from a small 320 x 200 to a GTV size.
1) Regarding dimensions in your layouts (values/dimens.xml):
values values-w600dp values-w720dp values-w1024dp
But does that mean that I should drop supporting those 4 density
containers? Or do I need to provide 16 resource folders, i.e. one for
every combination of density and size?
No, you don't need to provide different dimensions per dpi bucket (hdpi/xhdpi), because the dimensions are already being scaled up or down based on the device (if you're using dp instead of px). So for dimensions, you only need to provide values for devices with different sizes (hence the name, values-smallest possible width-600-dp). Because you don't want 16dp padding on a phone AND 16dp on a 10" tablet as well. You'd want 64dp instead. And no, it doesn't matter what density the device has. It still needs to have the same padding on the respective device width. So for dimens, you only need to think about the device's actual physical dimensions.
2) Regarding drawables scaling for different resolutions (drawables/xdpi):
The system scales them appropriately for the device. You don't need to worry about this. Also, you don't need to add any other buckets here. Just use mdpi/hdpi/xhdpi and maybe xxhdpi because many new devices are going to use the new density in the future.
Conclusion: there are 2 different UI building components that vary according to 2 different rules: drawables based on screen density and dimensions based on screen size. Do not mistake one for the other and think you need tens of buckets in the values folder, because that's not only wrong, it's just mind boggling.
I have images in drawable-hdpi(big images) and in drawable-mdpi(small images)
I opened my app on Kindle fire (its get layout from layout-large) and it use images from
drawable-mdpi , is any way to let app to get images from drawable-hdpi when screen size is large?
thanks
I think what you are looking for is to use configuration qualifiers.
It seems you are really misunderstanding what these folders do.
Your android will select folder based on it's screen size or pixel-density.
Your Kindle Fire has a medium Pixel density and a large screen. So it selects its resources from the res folders with those given qualifiers.
res/layout-large/my_layout.xml
and images from
res/drawable-mdpi/my_icon.png
You cannot tell your kindle to get images from the hdpi folder because it does not have a high pixel density.
So you could either create a folder called
res/drawable-large-mdpi/
specifically for your Kindle Fire device.
Or just make sure the right images are in the right folders.
EDIT: Size qualifiers are deprecated from 3.2.
While deprecated, they still work. Although results may not be what expected (for example: 5" and 7" are seen as same size -large-which still have difference). So they added dp qualifiers to use beyond 3.2. Which are much better. developer.android.com/guide/practices/… It kinda works like media-queries
Updating this with the new qualifiers for Android.
Use of size qualifiers such as drawable-large are deprecated in 3.2 or above.
To use the latest method of supporting multiple layouts and densities, you can use the following:
res/drawable-sw600dp-mdpi
In this example, sw600dprepresents the smallest width available to the activity in density-independent pixels,600dpin this case. This is deemed as being a little more fitting for device-specific layouts and drawables as the width is provided instead of a generalized size grouping such aslarge`.
There are also new options for available width and height, full information available here: Supporting Multiple Screens
All qualifiers are processed in the order they appear in Table2.
Read How Android Finds the Best-matching Resource.