Different values folders in android - android

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 :-

Related

dimen.xml is not being executed after specifying it for other sizes

In my project I just had a dimens.xml file and after completing my project I decided to create dimens files for other screen sizes.
So I began with creating values-mdpi directory and placing a dimen.xml file in it. but now every dimen resource I define in values-mdpi dimens file applies to all screens!
In other word the general dimens file is being ignored.
But if I define value-xxxhdpi an place the resources for my device in there is works fine. But why?
If I don't define a dimens file for specific density it must take resources from general dimens.xml, must not?
Density-specific resources will match the lowest-matching type.
So, if you make a values-mdpi folder, any device that's MDPI or greater (most devices) will use any existing values in that folder, and fall back to the default otherwise.
Your values-xxxhdpi folder likely doesn't apply to your device because your device doesn't match the XXXHDPI spec. It might be XXHDPI or XHDPI.
You should switch your logic. Instead of creating special layouts for low-density devices, create special layouts for high density devices.
Please make a folder named as "values-nodpi" and put general in that it should work there ! this should help!
NOTE!:its better to do it this way though android does provide support
for highdpi folders and also automatically regress it out for lower
ones but it affects performance

dimension folder for different screen sizes [duplicate]

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 :-

Android : the mystical technique to set different dimensions for different device / screen sizes

My first Android App. And, am trying to get this sorted -> setting different text sizes, layout sizes for different screen / device sizes. Now, I Googl'ed a lot , then read several Stackoverflow threads, & am doing this:
Created different folders under 'res' like
values-ldpi
values-mdpi
values-hdpi
values-xhdpi
values-xxhdpi
values-xxxhdpi
Then I put a dimens.xml & styles.xml in each folder above.
Phew! But this doesn't suffice. I want to have different textsizes (and other dimensions, am not speaking about images here) for phones & different ones for tablets. I know there are these 'values-sw600dp, and 'values-sw720dp' which they say is aimed at tablets. But even within each tablet size, I need to differentiate the different densities right? For example, within 'values-sw600dp', I need to have different textsizes for, say, hdpi, xhdpi, ... How do I do this? Any help please?
Here is an example of what am doing:
TextView textView = (TextView) findViewById(R.id.text_interference);
textView.setHeight(layoutHt);
textView.setWidth((layoutWd-20)/2);
int dimensControlButtonTextSize = getResources().getInteger(R.integer.CONTROL_BUTTON_TEXT_SIZE);
textView.setTextSize(dimensControlButtonTextSize);
Then in dimens.xml, it would be:
17
This value, i.e. 17 here, will differ in each device i.e. it is given a different value in each dimens.xml under each values- folder. I hope am clear.
Drawable resources do not need to be duplicated per screen configuration, except for special cases like you have a full screen splash that would be displayed differently for landscape and portrait. Normally for icons, specifying once in the main resources folder (under hdpi, mdpi, xhdpi, xxhdpi...) should be sufficient.
I would find screen configuration specific resources to be useful for dimen values, like padding, margin, width of items, etc...

Android scale image for XXHDPI

How can I make 2 separate layout folder for
screens that are xxhdpi, and screens that are everything else?
Thanks!
I have right now just a layout folder for all my layouts
You can have folders under /res that are named as follows (where "xxhdpi" refers to the Density):
layout
layout-xxhdpi
However, you may actually be referring to the Size of the screen itself, which can be:
layout
layout-xlarge
as an example...
Please refer to the Android Providing Resources docs for more information on the flavors of folder names for resources.

How does Android uses values folders?

I have the font size defined in my dimens.xml (e.g <dimen name="name_text_size">12sp</dimen>)
Since this size wasn't ok on all screens I created some additional folders with different values:
values-xhdpi
values-xlarge-mdpi
values-large-mdpi
I thought this should be enough, since before creating this layouts the text look ok on ldpi, mdpi and hdpi screens, but actually the font became too large. The problem is that I am not able to figure out from which file it takes the value now for these screens. Initially, I thought it uses the default value from the folder "values", but actually no layout is using that value. Can somebody help me understand(I sow Providing documentaion and Support Multiple Screens) how this folders are working and how could I optimize the number of defined resources (e.g. xhdpi and large-mdpi have the same values)?
The solution is simple create the following folders:
values-ldpi
values-mdpi
values-hdpi
But I don't want to make things more complicated than they must be.
Thanks in advance :)
You can provide the different string text in each Values-folder. Once it will run you can check from which folder its taking the string values.
You can achieve this by this trick.

Categories

Resources