I am creating an application which i try to support multiple languages. I put my english text in
values/strings.xml
French text to
values-fr/strings.xml
Now , i want to support multiple screens , too. I have these folders
values-normal-ldpi
values-normal-mdpi
values-large
values-xlarge
values
If user is French , and screen is large. it always choose strings from values-fr but dimens from values folder.. Should i have all of these values folder for french too (like values-fr-normal-ldpi etc. )? Is there any other way
Thank you.
For multiple screen support you need to create 4 different folder in res>layout folder of android structure
layout-hdpi
layout-mdpi
layout-xhdpi
layout-ldpi
layout-xxhdpi
each folder contains layout files of there respective dimensions and name of these files are same throug out all folders
also you need to create
drawable-ldpi
drawable-mdpi
drawable-hdpi and so on folder for different revolution images with same name
so smartly OS can detect resoltuion of device and from matching folder it shows images on your device
follow this link
http://developer.android.com/guide/practices/screens_support.html
about localisation your way is correct
Related
I want to have different dimens files according to each different screen density. I have done this by making the following procedure for each different screen size, but I have not created any new folder:
1- right-click on values folder
2- New-> Values Resource File
3- File name: dimens
4- Choose density qualifier
5- Choose the density that I want the dimens file to be attached to (example: X-High Density(xhdpi))
6- Click OK
So making this, I have in the values folder a dimens folder with all the different densities (but not a different folder for different densities, all the different densities files are in the same folder):
values/dimens/dimens(xxhdpi)
values/dimens/dimens(xhdpi)
values/dimens/dimens(hdpi)
values/dimens/dimens(ldpi)
...
It is working as expected, but I have seen many people that to do this they cereate a different values folder for each different density. So I am confused if what I have done is okay or I have to create a differnt values folder for each different screen density...
Image to let you understand what I have done:
I have in values folder the following:
I am creating different values folders in my app (values, values-ldpi, values-mdpi, values-hdpi, values-xhdpi, values-nodpi, values-w360dp-mdpi). But some devices that belong same category. But having different screen sizes. But I see give font size according to device densities in this the answer provided by #PankajSharma suggest to create folders like-
res/values/dimens.xml
res/values-small/dimens.xml
res/values-normal/dimens.xml
res/values-xlarge/dimens.xml
I want to know what is the difference b/w my way and the other way? I think the answer provided by #PankajSharma is easy. I also want to know which way is better?
The approach you are using is a valid approach, but a little outdated. From HoneyComb, there is a new way to fix all of this. Your resources folder should now look like this:
Please refer to the link I have posted and familiarize yourself with Smallest Width concept.
Hope this helps :)
EDIT: Adding to this post, try to establish some kind of standardization in your dimens.xml, something like this:
Doing this makes it easier to maintain code, plus it reduces the number of dimen folders. Normally rather than having values-hdpi, values-xhdpi, etc. files like values-sw480dp-xhdpi might have more values to adjust, but then again all of this is contextual.
Create a Single layout for default screens 4.7 inch (hdpi) in layout folder and dimensions in values folder. This is your Superset.
Now let say you want your layouts for 7inch devices. Create values-sw600dp folder for 7inch in Portrait orientation
Now lets say you want your layouts for 10 inch devices Create values-dw720dp folder
NOTE :- For landscape just add "-land" in front of folder names.
Now lets say you have new devices such as Xperia SP (4.7' and XHDPI) and Nexus 5(5" and XXHDPI).
For these, you can create values-xhdpi and values-xxhdpi folders and similary add -land for landscape orientation..
I hope you got the point of how to create folders..
Now your superset is defined in values folder. Most of the dimensions will be used from here only. Now run your app in other devices. Whatever mismatch is occuring just add that specific dimension in their respective values folder
To check from which folder your layouts, images are used, use my trick.
Create five same strings and put in it all the values folders like this :-
Default Screen
Screen 4.7
XHDPI Screen
MDPI Screen
Create five drawable folders, most of them will be already there : - drawable-hdpi, drawable-mdpi, drawable-xhdpi, drawable-xxhdpi, drawable-xxxhdpi
Put the screenshots below in their respective folder under the same name
This is how my res folder looks like and i am supporting all the devices from 4.7 screen and above :-
For support multiscreen devices android, typically using a drawable-xhdpi, drawable-hdpi, drawable-mdpi, drawable-ldpi for resources images. For using it with assets folder how to implement it? Do I need to create separate folder like assets-hdpi, assets-mdpi? Or what?
Assets folder is the folder using for stored raw data/resource such as media/audio files, text file or html ... which can be used for every screen size/density.
For support multi screen you only need to develop different layout/drawable file and put them into corresponding folder as you said above and don't need to make different raw data for multi screen.
No. You can't create such folders. But you can name your files different names (this example is for fonts) e.g:
font_for_large_screen.ttf - for big screen
font_for_small_screen.ttf - for small screen
and then have this strings in res -> values . As you may know, you can differentiate string values by screen sizes (and other characteristics). So, on on hdpi screen font value will be :
font_for_large_screen.ttf
on small :
font_for_small_screen.ttf
and you can grab appropriate font (or other file) from assets. Hope this will help you.
I am creating different values folders in my app (values, values-ldpi, values-mdpi, values-hdpi, values-xhdpi, values-nodpi, values-w360dp-mdpi). But some devices that belong same category. But having different screen sizes. But I see give font size according to device densities in this the answer provided by #PankajSharma suggest to create folders like-
res/values/dimens.xml
res/values-small/dimens.xml
res/values-normal/dimens.xml
res/values-xlarge/dimens.xml
I want to know what is the difference b/w my way and the other way? I think the answer provided by #PankajSharma is easy. I also want to know which way is better?
The approach you are using is a valid approach, but a little outdated. From HoneyComb, there is a new way to fix all of this. Your resources folder should now look like this:
Please refer to the link I have posted and familiarize yourself with Smallest Width concept.
Hope this helps :)
EDIT: Adding to this post, try to establish some kind of standardization in your dimens.xml, something like this:
Doing this makes it easier to maintain code, plus it reduces the number of dimen folders. Normally rather than having values-hdpi, values-xhdpi, etc. files like values-sw480dp-xhdpi might have more values to adjust, but then again all of this is contextual.
Create a Single layout for default screens 4.7 inch (hdpi) in layout folder and dimensions in values folder. This is your Superset.
Now let say you want your layouts for 7inch devices. Create values-sw600dp folder for 7inch in Portrait orientation
Now lets say you want your layouts for 10 inch devices Create values-dw720dp folder
NOTE :- For landscape just add "-land" in front of folder names.
Now lets say you have new devices such as Xperia SP (4.7' and XHDPI) and Nexus 5(5" and XXHDPI).
For these, you can create values-xhdpi and values-xxhdpi folders and similary add -land for landscape orientation..
I hope you got the point of how to create folders..
Now your superset is defined in values folder. Most of the dimensions will be used from here only. Now run your app in other devices. Whatever mismatch is occuring just add that specific dimension in their respective values folder
To check from which folder your layouts, images are used, use my trick.
Create five same strings and put in it all the values folders like this :-
Default Screen
Screen 4.7
XHDPI Screen
MDPI Screen
Create five drawable folders, most of them will be already there : - drawable-hdpi, drawable-mdpi, drawable-xhdpi, drawable-xxhdpi, drawable-xxxhdpi
Put the screenshots below in their respective folder under the same name
This is how my res folder looks like and i am supporting all the devices from 4.7 screen and above :-
I implemented the application which will supports the small screen ldpi and hdpi. It is working for only one either ldpi or hdpi. Because my application layout have some distance between the views. so i want differentiate the ldpi and mdpi. how to implement this can any body help me.
For this i am creating the layout-small folder in the res. is any name conventions like layout-small-ldpi (or) layout-small-mdpi or exiting or not. same like normal and large (layout-normal-ldpi or layout-normal-mdpi or layout-normal-hdpi). Please give the naming convention clearly.
thanks
In your res folder you have 2 folders:
drawable and layout.
You can add folders with a postfix with "-hdpi" for hdpi specifics, "-mdpi" for mdpi and "-ldpi" for ldpi.
So you should have these folders:
drawable-hdpi
drawable-mdpi
drawable-ldpi
layout-hdpi
layout-mdpi
layout-ldpi
You can also use specifics for landscape orientation or even SDK versions.
Read http://developer.android.com/guide/topics/resources/providing-resources.html for more info
To seemlessly support landscape / portrait mode, screen with different densities, you need to put appropriate "drawables" with following naming convention # res directory. res directory will be # root level of you application folder. For example LunarLander\res. res has different directories for storing images (drawables), layaout (for UI) and values (for font support).
You need to use the same name for all modes, this name shall be used in the application regardless of the mode.
Nomenclature is something like . (This may not be the exhaustive list) where type would be drawable / layout / values etc.
language would en / fr for english and french respectively. (this list is also not complete)
mode would be land / port for landscape and portrait respectively
density would be hdpi / mdpi / ldpi for high / medium and low density screen respectively.
Example
Suppose I have a background image, which needs to look differently for landscape and portrait mode. Then I will place two different images for background into res\drawable-land and res\drawable-port\ folder under the name background_image.png. I will refer to these in my application (or layout) using background_image as the name. The android system will appropriate choose the image based on the mode.
Same is applicable to ldpi / hdpi or en / fr.
Basically you need to create appropriate folder structure and keep the same name for entities. (string, drawable, layout etc)
Shash