I have developed a game in android,but i'm facing many problems with the screen sizes I heard that we should create separate folders like(layout-small,layout-normal,layout-large,layout-xlarge) in the res folder and should maintain all xml files in them.
But my confusion is how to retrieve particular xml from particular layout folder what is the code should be written in the Activity..?
Please help me to solve this by an example.
Thanks
you dont choose from which folder you read the xmls. Android does it for you depending on the dpi and the size of the screen its running on.
This is what helped me:
http://android-developers.blogspot.in/2011/07/new-tools-for-managing-screen-sizes.html
I believe Android does it automatically. The operating system detects when the display is a certain orientation / size and uses the layout from the appropriate folder (if present) without you having to do anything apart from create the layout files.
No you don't need to create xml for each screen size.
store your xml in your layout folder.
and as per the size (hdpi, mdpi, xhdpi, xxhdpi) create images.(read developer guide for image size)
Related
I have recently started creating an Android application using Appcelerator's Titanium.
Since in the application I requires to keep several images/icons with different sizes & dimensions essentially, So I need some advice on how I should organize them in the project.
And as you know like in Android project (Android studio or Eclipse with Android SDK) there is a predefined folder structure so if you want to keep any image then put them in all device sizes corresponding to the prescribed folders. So based on device sizes it will automatically detect corresponding dimension image from device preferable folder.
So does same approach can we achieve in Appcelerator's Titanium ?
Below is the default project structure for Appcelerator's Titanium project (5.1.2.GA)
As you can see there is 2 places where I can keep images. So can you suggest me where I can keep my images and how can I access them
Thanks, Any suggestion will be helpful for me. ~Chandan
Titanium supports platform, device and density specific images via folder and file conventions. I won't go into details here, but these two links walk you through:
How to use Device Specific Images
How to use Density Specific Images
The first part is used to be more specific about when these resources should be used. Images in sub-directories give us more control over when they are used.For example images that are in a folder named "res-long-land-hdpi" will be used for:
Long screens, such as WQVGA, WVGA, FWVGA
Device is in landscape orientation (horizontal)
High-density screens; approximately 240dpi.
Documentation Link
for me i deleted all folders in android/images (First) and i replaced them by folders in android/res (second)
like this
before when I was creating a new project I was found this folders drawable-hdpi,drawable-mdpi, drawable-xhdpi, and drawable-xxhdpi. but now they are all gone!
is there any explanation of what happens?
and where we should put our images?
This is perhaps because they will add an Gradle plugin that converts SVGs to PNGs during build (as mentioned in this IO talk). The idea is that you will only need to have a single SVG instead of multiple PNGs for various densities (an thus, only one drawable folder). You can still create the folders and use PNGs.
The Gradle plugins for SVG conversion by Google has not been released yet, but you can use Victor or a similar plugin if you already want to use SVGs for your drawables.
You should read Android Blog
you can just create drawable-xhdpi.
I just give answer here
read and if any problem ask.
I wasn't aware that Android Studio ever provided these dpi dependent drawable folders for the built-in default project scaffolding, and indeed, why should they?
Are they supposed to guess that you're going to support each and every one of these resolutions? Perhaps all your graphics will be vector graphics? Perhaps you only target low or high resolutions?
Also, the DPI modifier is only 1 of the possible modifiers you can attach to a resource folder. You can also add locale, screen width / height, mobile country code and many more. Should Android Studio create a folder with each of these options, along with every possible variation? You'd end up with thousands of folders which you'd likely never use.
In addition, creating a folder with no assets inside it is a big problem when you start synchronising your code using Github or something similar, and creating every possible folder with default assets inside seems like a huge waste.
I think the best approach here is to create any resource folder you need when you need it. Google leaves this decision to you.
Also, important: There is no XDPI or XXDPI folder - it's XHDPI, and XXHDPI
Check in your project section, Not in android section, If they gone just simply create them
In android project there are multiple folders, I know you can simply override these with one 'Drawable' folder.
My question is: When people download my app, will it take up more room if I have manually catered to all the different Drawable folders instead of just overriding them with one?
yea, but your app will be slightly slower, cause android has to re-size the images (whereas if you have different folders it uses the respective images)
Yes, different Drawable is for different dpi based device screen and its part of APK.
When you download APK then even drawable is also part of it and it gets stored on device and it does take space.
Different Drawable folders in android directory is for supporting different screen sizes. for better UI experience you should put drawables in appropriate folders.I think you should have look into it before proceeding further Know android project directories
My device configuration is large-mdpi. But in my app, i have the images only for small-ldpi,normal-mdpi. Here how to findout the best match for this. i think i collects the images from the small-ldpi because our precedence contains small as first.please see this link. is it right? please can anybody help me.
thanks.
Don't put size qualifiers on your drawable folders. Just make drawable-ldpi and drawable-mdpi.
Edit: Maybe I answered too quickly. Do you actually have different images for small and large screens at the same density? In that case, my advice is to always have a folder with a more general qualification. It's kind of like default in a switch statement.
In your instance, I'd go with:
drawable-ldpi
drawable-mdpi
drawable-large-ldpi
What is the difference between the three drawable folders in the res folder in the project hierarchy? If I have an image to put into a folder, which folder do I put it in?
I am going to take a guess that "the three drawable folders" are drawable-ldpi, drawable-mdpi, and drawable-hdpi. In that case, if you stick with all of those folders, you need to put one image in each, sized to match the indicated screen density. This is discussed in the online documentation as well as this blog post. You can find a set of sample projects showing use of different drawable resources based on screen density here.
If you are just starting out in Android development, you can get rid of all three of those directories and create a single drawable directory, putting your image in there. Eventually, though, for a quality application, you will want to test your images on different devices/emulators with different screen densities, and possibly have different images for each density to improve the look of your app.
Here is a reference to multi device options.
As said by #CommonsWare, you don't need to put resources in anything but res/ layout/ or drawable/ but if you want your program to have a better experience on multiple devices with different screens / density / languages you may want to consider that you have that option.
Also interesting, though not specific to images, is how android handles resources. It gives them a load order, where more specific means it'll get picked over less specific.
For example, you have three String values in strings.xml in your values folder. You also have one specific string in a folder called values-en. When android opens your app and your locale matches en, it will load two defaults from the values folder and the third, more specific string, from values-en. If your locale is ru, it will just use the default instead because you have no values-ru folder.
The same is true for images. If android can't find images for your specific screen variant, it will use defaults from the drawable folder.
In my opinion it's good practice to have default values/images in your generic folders like values/drawable and specific values/images in specific folders. This way both current and future devices will at least have a way to display your content until you can provide specific versions.