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.
Related
I have idea on separating values folder based on the size like ldpi, mdpi,hdpi,xhdpi,xxhdpi,xxxhdpi and small, large ,normal,large,xlarge . And for separating the folders based on language we'll use values-(language code). Apart from this can we separate the values folder base on both size and language? If possible how?
I want to show for small devices with font size of 12sp for one language and 18sp for another language. like values-small-te and values-small-en.
I tried with values-small-te but not worked :( . let me know if any way exists.
thanq in advance.
For language
you can write in String file that is you can create different files for different languange in string directorie
like
strings.xml(hi), strings.xml(guj), strings.xml(ta)
For font
you have to create different file in dimens directories to support different devices
like
dimens.xml(hdpi), dimens.xml(ldpi), dimens.xml(mdpi),
dimens.xml(xdpi), dimens.xml(xxhdpi), dimens.xml(sw480dp) ,
dimens.xml(sw600dp) , dimens.xml(sw720dp)
Please check this link to create directories.
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
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 am on one really big project that was started sins the time of android 1.5.
This project evolved as android was evolving and at this point supports 2.3 and above.
Now I got this problem I have a lot of drawables in drawable-hdpi,drawable-mdpi,drawable-ldpi but also in drawable folder.
Generally the concept of this 3 folders(drawable-hdpi,drawable-mdpi,drawable-ldpi) it is clear to me but my confusion comes with the images in drawable folder.
for example I have an image named myimage.png and this image is present in drawable-hdpi,drawable-mdpi,drawable-ldpi folders with resolution 72x72,48x48,36x36 respectively but this image is also present in drawable folder.
My question is why ? when does the image from drawable folder is used ? is this image forgotten to be removed ? of it is used in some cases ? I have tried to remove this image and the application works just fine. I also have put just a green color with resolution 72x72 and this image is never drawn
so can someone clarify me the existence of the drawable folder ?
I know that if I do not have the dhpi,mdpi and ldpi folders then I need to put the images in drawable but what is the point of images in drawable when this 3 folders are present ?
Thanks
EDIT
one more question, what if I have image in drawable-hdpi but not in ldpi and not i mdpi. Let say we have phone with mdpi resolution density... What will happen ?
drawable folder is used for default images if the images are not found in the respective folders then it will look into the drawable folder.
I found this phrase in the doc:
For example, imagine you have an application icon, icon.png, and need unique version of it for different locales. However, two locales,
English-Canadian and French-Canadian, need to use the same version.
You might assume that you need to copy the same image into the
resource directory for both English-Canadian and French-Canadian, but
it's not true. Instead, you can save the image that's used for both as
icon_ca.png (any name other than icon.png) and put it in the default
res/drawable/ directory. Then create an icon.xml file in
res/drawable-en-rCA/ and res/drawable-fr-rCA/ that refers to the
icon_ca.png resource using the element. This allows you to
store just one version of the PNG file and two small XML files that
point to it. (An example XML file is shown below.)
Please refer this link for more clearity.
AFAIK you don't need drawable folder if you have all three types of folder (drawable-hdpi,drawable-mdpi,drawable-ldpi )with different resolution images.
As per I faced when you run the app on Android 1.5 and 2.0 if the images which is used in any layout is not available in folder 'drawable' then the project gives error "Resource not found" even if the image is present in other hdpi,mdpi or ldpi folder.
This is not about the densities there are other qualifiers as well, though in most of the cases we don't use them much. For list of qualifiers check here and here. You can use -finger -language ... etc qualifiers. In case you want to provide qualifier default resources[in this case drawable] you can opt for default drawable folder. Or many default folders without qualifiers added behind them
I think this page should help you understand better. Thank you for the question. I, myself, didn't know the answer. Basically you have 4 different versions and if no exactly matching version exists, the default one (without qualifier) is used.
I am new to Android and I need to use images in my XML file.
A tutorial says that I have to place them in drawable directory, but I can't find it as I find drawable-hdpi, etc.
drawable folder is divided into into three part according to device screen size h- high, M- Medium, L- Low because in android different size of device available in the market and android device screen divide into three type h,m,l based on density specific according to device size android pick the image from specific drawable folder h ,m ,l if you dont want to density specification in your application then add new folder with the name of drawable.
I hope it is more use full to you.
You can create the drawable folder yourself by right-clicking "res" -> "New" -> "Folder" and naming it drawable.If you do not need your images to be density-specific, you can put your images there.
you can create your own drawable folder in res directory. But remember keep the images in that folder which are common for all screen size devices. drwable-hdpi means this directory contained the images will be loaded when the device has higher dpi. similarly drawable-mdpi and drawable-ldpi are there.
Those which you found are drawable folders.. Insert the images in all three of them. So that at time of change in definition of screen images can be changed accordingly. For now, Insert same image in all three of them.
You can create your own drawable folder. But its good to use these at first then when you run your application on device you will come to know the difference.
drawable-hdpi drawable-mdpi etc are the different type of drawables . you can keep your images in these folder (any one at the initial level).
But they have some diffrence according to the resolution of the screen & density of android device. Further you can check the diffrence between them and keep the images as per need.
see this for more details: Explain the difference between drawable, drawable-ldpi, drawable-mdpi and drawable-hdpi
and Supporting Multiple Screens
you can create a drawable folder in the /res folder of your project and put your images there.
drawable-hdpi(mdpi/ldpi) are used separate different resources for different type of screen. take a look here to know more about multiple screen handling
I realize that this question is rather dated, but...it came up when I Googled the issue of inserting images into an Eclipse Android project, so....
Actually, those folders are mipmaps and they are used by the graphics subsystem to provide seamless zooming, as well. I would suggest creating proper mipmaps using an editor, as opposed to providing only one resolution choice.