Android studio different screen sizes res folder - android

I have a question regarding android supporting different screensizes. I would like to know if it is necassary to add the different sw folder for example layout-sw24odp manually to support different dip modes. When I wouldnt add these folders would the application scale automatically in each device? Or do I need to provide the folder containing the layouts, to support different densitys?

It is only necessary if you are not getting the results you expect for a particular mode. In general I'll have separate folders for drawable-hdpi, drawable-mdpi, drawable-xhdpi, drawable-xxhdpi and similar for layout- and values-, I'll only populate those if I have a layout that is not working the way I want on those devices.

Related

How to specify icons for different densities screen?

While working on an app, I noticed that there are different files such as drawable and drawable-hdpi. So I found out that these folders are for different icons and images size. My problem is that these two are two separate folders and I was wondering if I have to direct the android to the icons in the separate folder?
By that I mean do I have to first figure out what kind of dpi the device is and set the appropriate icons or can I just declare one drawable resource and android will figure it out for me?
If I can just set an icon name and the drawable file and the android system will know what to use for the different screen, then can you explain to me how this is done? I mean it is two separate files drawable and drawable-hdpi. So how can just set an icon image in the drawable folder and android knows what to access for the drawable-hdpi for the different device?
There are several questions bundled in one, but I will explain all of them in detail.
As you know, there are a variety of Android devices with different screen sizes. That is why, they are separated into a few categories based on their density. Must read this, if you haven't already.
This is the full classification,
So the idea is to have all these directories separately and not just a single "drawable" folder. Whenever you want to put any image or icon in your app, you need to put different sizes of them in their respective directories correctly.
two separate folders and I was wondering if I have to direct the
android to the icons in the separate folder?
You do not have to direct Android to do anything. Android will automatically pick the right image size from the "drawable-**dpi" intelligently.
By that I mean do I have to first figure out what kind of dpi the
device is and set the appropriate icons or can I just declare one
drawable resource and android will figure it out for me?
You can't figure out dpi of all devices, as your app will run on several devices having different densities. You just need to put different sizes of your icons in their respective drawable directory.
You should never put a single image or icon in the "drawable" directory as it can drastically slow down your app as Android need to dynamically resize your images at runtime.
If I can just set an icon name and the drawable file and the android
system will know what to use for the different screen, then can you
explain to me how this is done?
Just refer to the previous question, its already answered.
So how can just set an icon image in the drawable folder and android
knows what to access for the drawable-hdpi for the different device?
As explained earlier, Android obviously knows which device the app is currently running and thereby knows its screen density. Now it is very easy for Android just pick the right image based on the current screen density if you have put them properly in their respective drawable folders.
UPDATE
Just to answer your new question.
You start out with one "drawable" folder. But you need to create the other directories yourself and they need to have the proper name like drawable-mdpi, drawable-hdpi, drawable-xhdpi, etc.
You cannot have any other name like drawable-K or drawable-l, or not even a spelling mistake in the names. Android just scans to see if the folders with these names exists in your app, if so, then it will pick right one.
Suppose you are using a Nexus 5 which is an xxhdpi device,
i) Now Android will look for the drawable-xhdpi directory in your app for a particular image.
ii) If it exists, then it will just pick it up. If it doesn't then it will look for the nearest ones like drawable-xxhdpi or drawable-hdpi and resize the image slightly to fit.
iii) If nothing exists, then it will pick the image from the raw "drawable" folder.
Hope it clears all your doubts.

Inflate from layout-v10 folder on a hdpi gingerbread device?

I'm having both layout folders "layout-v10" and "layout-hdpi" in my application. However, as some gingerbread(which is API Level 10) devices also are hdpi screen size, the layouts under the "layout-hdpi" folder is getting inflated. I want to force the layout from "layout-v10" folder to be inflated for all gingerbread devices even if it is a hdpi. Is there any way to do so?
I read this link http://developer.android.com/guide/practices/screens_support.html couldn't figure out what can be done to solve my problem.
to keep layouts looking good in all devices we don't provide folders like "layout-hdpi", etc.
U need to keep your resources in drawable-hdpi, drawable-xhdpi, etc. as mentioned in the android developers guide. The android system chooses the correct folder based on the screen density. This works independent of the api version you are using, the layout will look good in all api levels if you are defining your resources correctly acc. to different screen densities.

Will layout folders fix the tablet compatibility?

I read a few things about how to make your app compatible with tablets. Some say about using your code and some say about the layout folders or some about the sw600dp and sw720dp folders. I am really confused and am not 100% sure which is the most simplest way to just make it play on a tablet.
What i did is i made 3 more layout folders (large, xlarge and small, I already had the drawable classes in all sizes but i didnt change the size of the images, its in all drawables the same size) and in these 3 extra folders i copied the same files i had in the plain layout folder. So i have 4 layouts with all the xmls the same.
Will this make it compatible with tablet and fix my issue?
for Xlarge use this folder drawable-xlarge-hdpi
for large use this folder drawable-large-xhdpi
layout-large (7 inch)
layout-xlarge(10 inch) folder are used for layouts
The Simplest way to make your app adopt to different hardware configurations is using folders. The framework will do all the work for you. (tutorial)

How my android app will run on multiple screen resolution devices?

I have developed an android application and run it on an HVGA emulator. It's running successfully on any HVGA device i.e. mdpi. But if I try to run on small screen resolution devices i.e QVGA then my buttons are looking as if they go down and dont fit onto the small screen...
So how can I run my android application on multiple screen resolution successfully?
follow these instructions
create a folder in yourAppFolder/res/ named layout-small (*more on this subject later)
insert in this folder all your xml layout items that need special treatment for a small screen (it is not necessary to copy all of "normal" layout files, but you can if you wish)
change the files in this layout as needed
What happens with this approach:
if the device has a non-small screen, the default layout (the one in "layout" folder) will be loaded and used, otherwise if the screen is in "small" category the files in "layout-small" will be used instead (only if one with the same name is available, otherwise the one in "layout" will be used
*About folder naming: that policy was the old one supported by android. Nowadays there is another one, more precise but more complex too (example: specify minimum necessary width). Anyway, this is still supported, just note that eclipse may suggest you some alternatives. Currently, i am still developing with the old naming policy.
I think it is better to design your layout for every screen size and resolutions. It is easy in android. Copy your layout from "layout" folder of resources and paste it in the "layout-land", "layout-xlarge", "layout-xlarge-land" and ... folders and change those settings you need in them.
you can check this link:
In the UI builder (part of the Eclipse plugin), you can build your interfaces for multiple screen sizes and resolutions. To make different layouts for different resolutions, simply follow these instructions to build alternate layouts:
http://developer.android.com/guide/practices/screens_support.html#support

Android muliple screen support?

I have to design an application which to support under three resolution. for that i use the code in manifest
and also create three folder layout , layout-large, layout-small for supporting three resolution, correspondingly i put the different resolution of image in drawable-hdpi ,drawable-ldpi ,drawable-mdpi , but whenever i run the app in different resolution it going to take low resolution image instead of different resolution i use.
I don`t know where i made the mistake, whether i have to add some code in layout xml or not. I also search the android developer forum and i do the application design as they insist.
Any one suggest some idea to achieve this.Thanks
There are two things you could check: have you set the minimum SDK version of your app to use version 4 (Android 1.6) support for this started?
Secondly, the layout-large and layout-small folders are designed for different sized screens (think tablet vs phone), and not resolution. If you're changing the resolution (DPI) of the device, you'll need to use layout-hdpi, layout-ldpi etc.
Further, if it's only the images you're changing, you should be placing the different images in drawable-hdpi, drawable-ldpi etc, and not layout-xxxx. If on a supported device, Android will pick the image from the correct folder, so you'll only have one layout folder (or 2 if you use layout-land)
Some (or all :S) of these points are covered in this link, to another question on StackOverflow. Try to use the search function before asking a question. Also, you'll find people are more receptive to providing answers to users with higher accept percentages.
Android - layout-large folder is been ignored
Edit: for multiple screen support, also look at Fragments to better organise and fit your content for both large and small screen devices (dev.Android, worked example)

Categories

Resources