I am developing a game and want to support all screens which have 240dp density. These screens lies in hpdi-category of Android e.g. some tablets like 10.1" and 7.0", some phones which have 480*800 screens, etc. Can you please tell me how to provide alternative drawables.
Thanks in advance.
Just put the drawable files into the drawable-hdpi or drawable-mdpi folder respectively.
For full control depending on your needs you might want to check http://developer.android.com/guide/practices/screens_support.html
Here you find all the possibilities...
You may especially check the new size qualifiers. In particular (also from the link above):
For other cases in which you want to further customize your UI to differentiate between sizes such as 7” and 10” tablets, you can define additional smallest width layouts:
res/layout/main_activity.xml # For handsets (smaller than 600dp available width)
res/layout-sw600dp/main_activity.xml # For 7” tablets (600dp wide and bigger)
res/layout-sw720dp/main_activity.xml # For 10” tablets (720dp wide and bigger)
Answering the next question, you can qualify for the whole range of options, from current locale to display width/height. See http://developer.android.com/guide/topics/resources/providing-resources.html#AlternativeResources
You can use size or density qualifiers for your drawable folder. If you for example have a fullscreen background drawable for a tablet and for a phone you can create a drawable-xlarge folder. This folder will be used on a table only. You could also combine the ressource qualifiers like drawable-xlarge-hdpi. For more information on this read Providing Ressources.
I would suggest to specifiy your layout by screen size only. Resulting in four layout folders layout-small, layout-normal, layout-large, layout-xlarge. The normal drawables that only need a bigger resolution with a higher screen density like buttons or other stuff that is shown in the same size on phones and tablets should be put into the density dependent folders like (drawable-ldpi, drawable-mdpi, drawable-hdpi, drawable-xhdpi).
Related
When I create small,normal,large,xlarge layouts:How Android Detects Screen Size phone for use this layouts?base on dp or dpi or px?
Is the result always right?Because some devices are smaller in physical size but the density is higher so if based on density this detect is not always correct.
Am I right?
Android uses dp, but there are a lot of variants you can create in your resources for example
res/layout/main_activity.xml # For handsets (smaller than 600dp available width)
res/layout-sw600dp/main_activity.xml # For 7” tablets (600dp wide and bigger)
You can cover more resolutions using different configs, but I think is hard work to cover everything, because how I said we have different resolutions, screen sizes and now we have notch.
res/layout-560dpi/
res/layout-ldpi/ ...
Bellow, I copy a link about this
https://developer.android.com/training/multiscreen/screensizes
I finished to develop (application part) the app for my project, but now I have problems with the layout. I created the following folders and edited the xml file:
layout (default)
layout-large
layout-normal
layout-small
layout-xlarge
On my smartphone (Galaxy S Advance - screen 800x480), the layout is ok, colleague's smartphone (HTC MINI ONE - screen 720x1280) the app haven't got the appropriate layout. In both cases (my smartphone and colleague's smartphone), android loads layout-normal.
What's wrong ???
Thank you
Please mind screen densities for layouts. Even though you put layout files in appropriate layout containers it does not mean in anyway that Android will respect the folders as densities too play an important role in the way how Android selects the correct layout.xml file.
Any device less than 5 inches will fall under sw320dp category your solution would be then to create separate folders named layout-sw320dp-ldpi, layout-sw320dp-mdpi, layout-sw320dp-hdpi, layout-sw320dp-xhdpi and layout-sw320dp-xxhdpi and put the corresponding xml files in them.
Similarly you can approach other screen sizes like layout-sw600dp and layout-sw720dp etc with above screen densities.
You can create different layouts for different Screens width instead of just create small and large dpi folders, in this method you will just have one drawable folder contains all of your resources and multiple layout folders, the main one called layout and contains the default layouts in order to run the specified layout in case it didn't find it in another layout folder, and the folders hierarchy as described in android developers page will be like :
res/layout/main_activity.xml # For handsets (smaller than 600dp available width)
res/layout-sw600dp/main_activity.xml # For 7” tablets (600dp wide and bigger)
res/layout-sw720dp/main_activity.xml # For 10” tablets (720dp wide and bigger)
and for example if you want a customized layouts to 340dp screen width you will create layout-sw340dp folder inside res folder, So it will be like
res/layout-sw340dp/main_activity.xml
and the program will automatically assign the layout to the appropriate folder according to the device width.
As you provide layout-large layout-normal layout-small layout-xlarge 4 layout categories. The layout folder(without any qualifier) will be useless. All devices will fall into the other 4 screen buckets.
From your description, I guess you should remove layout-normal folder from your resource.
In addition, normal, large and the other two are just "ranges". If you want more accurate control over screen sizes, you can use layout-sw
Please Remove loyout folder for Your app Besouse The layout folder will be useless
Galaxy S Advance - screen 800x480 layout-hdpi
For devices having 720 * 1280 resolution, you can use layout-w720-h1280 folder
Which are the value folder names and layout folder names that I can used to support multiple screen sizes and dpi values. Looking for the complete list of devices with 4.1+
Thank you
-For layouts you can specify
res/layout/my_layout.xml // layout for normal screen size ("default")
res/layout-small/my_layout.xml // layout for small screen size
res/layout-large/my_layout.xml // layout for large screen size
res/layout-xlarge/my_layout.xml // layout for extra large screen size
res/layout-xlarge-land/my_layout.xml // layout for extra large in landscape orientation
-- If you want to specify the screen basing on the dp you can spicify the name as
res/drawable-mdpi/my_icon.png // bitmap for medium density
res/drawable-hdpi/my_icon.png // bitmap for high density
res/drawable-xhdpi/my_icon.png // bitmap for extra high density
-- If you want to specify basing on the smallest width you can specify as
res/layout/main_activity.xml # For handsets (smaller than 600dp available width)
res/layout-sw600dp/main_activity.xml # For 7” tablets (600dp wide and bigger)
res/layout-sw720dp/main_activity.xml # For 10” tablets (720dp wide and bigger)
[for more detail click here][2]
Under your project, you will find a folder called "res". You need to supply different images to different screen sizes inside the drawable folders.
For example, inside the folder drawable-hdpi you will add your hdpi images, inside the folder drawable-mdpi you will add your mdpi images and so on...
Also, if you have a missing folder, for example for the xxhdpi dpi, you can just create the folder under the res folder (drawable-xxhdpi) and add your xxhdpi images.
What I have in my project is:
values-small;
values-normal;
valuse-large;
valuse-xlarge;
these folders contain the dimensions of the images and texts for all the screen sizes;
But should I add hdpi,mdpi... although I've added the size of the image in dp, and the size of the text in sp..?
example:
<dimen name="btnwidth">60dp</dimen>
<dimen name="btnheight">60dp</dimen>
<dimen name="fsinlistview">25sp</dimen>
because I am not getting the needed result on all the devices...
So why the dp and sp aren't being fixed depending on the screen dpi?
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-sw320dp folder for 7inch in Portrain 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..
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
The answer from #RahulGupta is pretty flawed. You should more follow what #amalBit has written.
As mentioned in my comment, the basic idea is to have a very flexible layout with some basic "cross screen" settings that you can and should follow
For example: The Settings list has on a phone maybe 16-32 dp margin on the sides, on a xlarge tablet like the Nexus 10 it has a way bigger margin. I highly doubt that the Settings screen was built with dozens of dimens files to fit all and every screen resolution, dimension and dpi. I guess that is basically just using one default for all and for the bigger tablets it is using a bigger value. So maybe a differenciation between 320dp and 720dp.
My suggestion: Start small with one layout, one dimens.xml file in your values folder and use a normal phone for your development. When you have done the layouting on it, check it on different screens and see if you need to modify something. Normally on a low res/low dpi device, the paddings/margins and sizes should scale correctly and in a good visual way.
The biggest "issues" you will face with 7"+ tablets and for them I would just start by creating a separate dimens.xml file and increase the dimens I need to make it better looking.
Normally the default values folder should contain 80% of your "style", the rest are just additions to make them fit perfect.
Check this link Supporting multiple screens.
From the above link:
320dp: a typical phone screen (240x320 ldpi, 320x480 mdpi, 480x800 hdpi, etc).
480dp: a tweener tablet like the Streak (480x800 mdpi).
600dp: a 7” tablet (600x1024 mdpi).
720dp: a 10” tablet (720x1280 mdpi, 800x1280 mdpi, etc).
Check out this converter.
We would like to design layouts for specific resolutions as below:
Samsung Duos: 480 X 800 Android Version 4.0.4
HTC Velocity: 540 X 960
To do so we have created layout folders for each as below:
layout-w480dp-h800dp
layout-w540dp-h960dp
Assuming that if we run application on samsung duaos it should pick the layouts from
layout-w480dp-h800dp folder but it is giving error and unable to start activity.
The error is:
android.content.res.Resources$NotFoundException: Resource ID #0x7f030029
It means it could not locate the layout required by the activity. Same happen with HTC Velocity.
Are we doing something wrong?
Please let us know if you have any idea.
must have been a problem with some resource try to delete a image file from drawable and add it again build the project it should run
Did you try to Clean and Build? It usually help as looks like R generation was corrupted
Your assumption is wrong.
layout-w480dp-h800dp isn't for 480x800 px screen.
DP is way Different than PX. Please read this http://developer.android.com/guide/practices/screens_support.html.
Are you sure you really need different designs for so similar handsets? I would say this is pointless.
In my opinion at most U should distinguish 3 types of devices.
res/layout/main_activity.xml # For handsets (smaller than 600dp available width)
res/layout-sw600dp/main_activity.xml # For 7” tablets (600dp wide and bigger)
res/layout-sw720dp/main_activity.xml # For 10” tablets (720dp wide and bigger)
If you still want to do what you are trying to do you can try px instead of dp. But Im not sure if this will work ...
Do you have a default layout that relate to your activity?I mean each folder containing the layout of the same name.