1
\$\begingroup\$

I have looked through all of the android docs and many stack overflow questions, and I have a question on supporting multiple screen sizes. If I have some drawables, I know I need to put them in folders like these:

enter image description here

But does android make these folders for me? When I try copy and pasting my images into the drawable folder, I get something like this:

enter image description here

With no directory names. So do I have to manually make those directories, and then will android automatically pick the right image to use depending on the screen size?

I have the same question for the layout. For example, I know that to support many screen sizes, I need to put the layout in many folders like this:

enter image description here

But right now, my layout is like this:

enter image description here

So must I manually create each layout folder, and then copy and paste my current layout into the new layout folder, and then go into each layout, and render it until it looks nice on the android design tab of the XML? Then, will android pick out the best layout depending on the screen size for me?

Thanks so much,

I have been delaying making my app compatible in different layouts because of these questions, I hope they can get answered!

\$\endgroup\$
3
\$\begingroup\$

I recommend you read this first if you haven't already as it explains all about different resource folders: http://developer.android.com/guide/topics/resources/providing-resources.html

The most important fact is that it's all just about the name of the folder, so yes you could create the folder manually if you wanted to just following the naming scheme used in the article I gave you. However since you seem to be using android studio I'll show you how you can do it there since it has some built-in functionality for it.

Also yes, android will automatically get the right resource for you. If you have multiple different my_circle.png files in different folders with different constraints, R.drawable.my_circle with only return the image in the folder that matches the current device specifications. The exact algorithm it uses to select the resource is in the article.

First with any layout open you can click the top left button in the editor to change what layout you want to be working on as well as create new layouts.

Make new layout file

Here is the "folder maker". You can select any constraint on the layout on the left, like if you what the layout only to be used if the user has a certain screen size, screen density, language, etc. Just add the ones you want and notice that it changes the directory name to match.

Resource type selector

Now your new layout is available on the left. In the android view, the folder name of the layout/resource is in is given in parenthesis. If you do it this way android will automatically make a layout XML file for you, instead of just creating a folder and copying it over like you mentioned.

Made new layout file

However it's still in it's own folder if you change to the project files view. This shows how the res folders/files are actually stored.

New layout show in file hierarchy

To create something similar for images or other resources, just right-click the res-folder and create a new android resource directory. You'll be presented with the same "folder maker" as before except that's it's no longer locked on type layout and you have to change the type yourself to e.g. drawable or whatever resource type you are adding. This will then create a drawable folder with the correct name for you to drag-and-drop your images into.

Make new folder for image drawable

Here I created a folder using a size constraint of normal. Your may have to be in e.g. the project files view to be able to drag over files as the folder wouldn't show up in the typical android view. If you wonder how to change view, just click the drop-down on the top of the image.

The drawable folder

Remember to always include a default resource folder, one with no constraints. Otherwise your app will crash when the constraint aren't met.

\$\endgroup\$
  • \$\begingroup\$ Remember to always include a default resource folder, one with no constraints Wait...doesn't android studio already do that for me? Also, what do you mean by no constraints? \$\endgroup\$ – NullPointerException Dec 3 '15 at 4:07
  • \$\begingroup\$ Also, do i need to create a separate layout-landscape for each size? \$\endgroup\$ – NullPointerException Dec 3 '15 at 4:10
  • \$\begingroup\$ Also, do I need to specify any other layouts in order to be optimal for all screen sizes? Here is what I got so far: snag.gy/GTy6h.jpg \$\endgroup\$ – NullPointerException Dec 3 '15 at 4:15
  • \$\begingroup\$ Also, do I need to specify anything in the manifest to make my app available for tablets etc.? \$\endgroup\$ – NullPointerException Dec 3 '15 at 4:16
  • \$\begingroup\$ Thank you so, so much. Your long and detailed answer is super helpful. I will mark it best answer once I get my questions answered. For now, I have liked! :-) \$\endgroup\$ – NullPointerException Dec 3 '15 at 4:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.