Supporting Multiple Screens with size qualifier - android

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.

Related

How does the OS detect the screen size?

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

Can anyone explain me how to make android app which can fit on most of devices screens?I did not understand any thing from documentation

When I try to make some android app then it seems very good for some devices but on some other devices(mostly which have a lower android API version) it does not look so much better. Sometimes some view (like button)goes out of the screen size.
I have read the documentation provided by Google.But I did not understand anything.As I am a new learner so it is creating many problems for me. If anyone has some time then please help me to understand this thing in the easiest way.
Thanks in advance.
most of the time i uses ssp and sdp. The ssp a scalable size unit for texts is android SDK that provides a new size unit - ssp (scalable sp). This size unit scales with the screen size based on the sp size unit (for texts). It can help Android developers with supporting multiple screens.and sdp This is the sibling of the sdp size unit that should be used for non text views.
[https://github.com/intuit/ssp][1] and [https://github.com/intuit/sdp][1]
use gradle and compile libraries like below
compile 'com.intuit.sdp:sdp-android:1.0.4'
compile 'com.intuit.ssp:ssp-android:1.0.4'
in your layout activity xml for example for text you can provide like this
android:textSize="#dimen/_16ssp"
for layouts
android:layout_height="#dimen/_16sdp"
this will take care for any screens enjoy.
Please go through this https://developer.android.com/guide/practices/screens_support.html
For layouts 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)
res/layout-sw600dp-land/main_activity.xml # layout for landscape mode.
For example, see below pic

different layouts for different screen size

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

Android resolutions and emulator not choosing correct image

I have a quick question regarding Android resolutions and how it is represented on the emulator. I have set up a test project to test many different resolutions and how they look on each orientation. So I have created drawable-land-ldpi,mdpi,hdpi-xhpdi and done the same thing for drawable-port. I also have all the layout folders, i.e. small med large x large, small-land,med-land,large-land, x-land
I have created 8 test images, that just say small port, land, medium port, land etc and so on just to check Android is choosing the correct image. I have also created a layout file for each layout folder, in the layout files I have a text field which just specifies the folder name so I know which layout folder is being used.
I have two questions, first is am I creating the correct image size for each folder. The image sizes I have created as are follows
drawable-land-ldpi - 320 * 240
drawable-port-ldpi - 240 * 320
drawable-land-mdpi - 480 * 320
drawable-port-mdpi - 320 * 480
drawable-land-hdpi - 800 * 480
drawable-port-hdpi - 480 * 800
drawable-land-xhdpi - 1080 * 720
drawable-port-xhdpi - 720 * 1080
And my second question is why do these not seem to represent properly on the emulator? Example, I have created an Android app with one screen and the images in the appropriate folders. I have created two emulators, one is 2.3.3, and one is a 3.0 tablet.
If I run the device on my device which, it uses the image from the medium resolution folder and uses the medium layout folder. So if it is port it will use the layout from the default layout folder and the image from the drawable-port-mdpi and if its landscape it will use the layout from the default land folder and the image from the drawable-land-mdpi.
However if I run this on the emulator, on the 2.3.3 device, it uses the layout folder from the medium layout folder, but the image from the drawable-hdpi-port and if its landscape uses the medium landscape layout folder, but the image from the drawable-hdpi-land. If I run it on the 3.0 tablet emulator, it uses the correct layout from the xLarge port and xLarge land, but it uses the image from the drawable-mdpi folders.
I have set up in the manifest to support all resolutions and layouts. Is there any reason why the emulator is doing this? I don't have an Android tablet on me at present to test this as friend forgot to bring it, so I can't test if this works fine on the tablet yet.
I would like to be able to use the emulator to try out a range of devices to test, but if it is not choosing the correct image then I cannot rely on it. Anyone else have issues like this? Or am I doing something wrong?
Any information would be much appreciated!!
Pixel density matters. For instance, your hdpi images may be the right size, but with an incorrect pixel density, they will still get scaled in those folders. For instance, your hdpi images should have a pixel density of ~240dpi. Check the developer guide for supporting multiple screen sizes:
http://developer.android.com/guide/practices/screens_support.html
Another issue is that the screens may be a variety of sizes, along with different pixel densities, e.g., a tablet could be 10 inches (X-Large), but still have a medium pixel density (1280x800). At the same time, you could have another tablet that's also 10" with xhdpi, if the resolution was something like 2560x1600.
It might be better for you to specify your actual layout folders based on pixel density. i.e., you can make folders:
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 you can still apply port and land to them. Read up on the page about supporting multiple screen sizes, it will probably really help to answer a lot of your questions.

Alternative Drawables

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).

Categories

Resources