how to design android cocos2d app for multiple screens - android

I am working on Cocos2d Android,in cocos2d images are saved in assets folder, here we can't take images ldpi,hdipi,mdpi images. So which size images are best for supporting multiple devices(phones and tablets). I have taken small size image(240x320), I am resizing images, so its supporting for all devices, but images are looking blur. so which size image is best to support all screens both tablet and phones. Please suggest me.

the best way is taking the highest resolutions pictures ie. the size of the highest android screen size. and cocos2d will adjust for small android phones according to the screen sizes. Blur will happen when you take small images and enlarge it for big screen android phones.
But if you use multiple png files it increases the app size.
source-I made a game using cocos2d in android.

This is how you can arrange stuff in project
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
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
and this link will tell rest of the story

Related

How does android choose the right layout/drawable for the correct screen resolution?

I that When starting an android application, android makes a good "guess" as to which layout/drawable to use depending on the screen size. However, I was wondering where it chooses this from? I ask this because I have quite a few layouts which don't all work. I read on the android website that you can make a folder called layout-xhdpi, layout-ldpi... etc. But does android automatically look for layout-xhdpi or layout-ldpi or do I need to specify that anywhere?
Same goes for drawables. When creating a new application in Eclispe it makes automatically drawables folders for you but does this necessarily mean it looks for those.
Conclusion:
Where does android look for alternative screen sizes and how/where can I change that?
Create following layout folder
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
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

xml for multiple screen in android

i am working on 2.2 version of android and xml is designed according to this version
Specification of emulator : version 2.2, Built-in : HVGA , Memory : 1024
and now i need this application to be transformed into 4.0 version of Samsung galaxy s3 but the screen are very streched and does not look good
thanks in advance if any help.
You have to create multiple resources for your app. Android has 4 resolutions (ldpi,mdpi,hdpi and xhdpi) and 4 generalized screen sizes (small, medium, large and extra large). So you have to make 4 layouts (or 3 if you don't plan on supporting tablets, since tablets come under the extra large category) to support the screen sizes.
Here's a general guide:
put layouts for small, medium, large and extra large in your res/ folder as follows:
res/layout/sample_layout.xml // default layout
res/layout-small/sample_layout.xml // layout for small screen size
res/layout-large/sample_layout.xml // layout for large screen size
res/layout-xlarge/sample_layout.xml // layout for extra large screen size
you can also use
res/layout-land/sample_layout.xml for landscape orientation for all screen sizes or you can target landscape layouts for specific screen sizes as res/layout-medium-land/sample_layout.xml
note that all the layouts have the same name.
once you have your layouts ready, you need to take care of image resolutions also
once again in your res/ folder add images like this:
res/drawable-ldpi/sample_image.png // low density
res/drawable-mdpi/sample_image.png // medium density
res/drawable-hdpi/sample_image.png // high density
res/drawable-xhdpi/sample_image.png // extra high density
once again, all the images have the same name.
general guidelines for designing images are:
ldpi is 0.75x dimensions of mdpi
hdpi is 1.5x dimensions of mdpi
xhdpi is 2x dimensinons of mdpi
generally, I design mdpi images for a 320x480 screen and then multiply the dimensions as per the above rules to get images for other resolutions.
Android will automatically select the best combination of layout and image depending on the device. For example, for a high resolution medium size device, layout-medium and high density image will be displayed to the user.
Make sure you create emulators for all these combinations and test your app thoroughly. here's the official docs for more info:
https://developer.android.com/guide/practices/screens_support.html
You have to maintain your xml files in
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
Check this Supporting Multiple Screens for how to design your layout for supporting multiple screens
and also for images use
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

Using different resources for different layouts. Layout distinctions

I've got a layout-normal and layout-large. Additionally, I provide several splash images with different resolution: 480x800 and 1280x800.
My problems are:
In my task it's said that I must distinguish layouts based on device resolutions(one for 480x800 and the other for 1280x800). Is there any possibility to implement it ? Taking in consideration an assumption that handsets have 480x800 resolutions and tablets - 1280x800 and higher, I could implement this scheme but I'm not sure that it's true.
I've created a test project where I attempted to distinguish layouts based on size, but I can't make android use 480x800 image for layout-normal and 1280x800 image for layout-large: in both cases it shows the 480x800 image. I guess, it's because of size, in case of a device, not equals resolution, in case of an image. However, I need to provide completely different looks for 480x800 and 1280x800. what are my options here ?
Thanks.
PS I'm building against Android 2.3.
You have the "Supporting Multiple screens" documentation that helps on that matter.
For example, the following is a list of resource directories in an application that provides different layout designs for different screen sizes and different bitmap drawables for medium, high, and extra high density screens.
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
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

Android build Layout for all device

it is possible to build layout (ex: menu)
that will use coordinates system pt
I need to build menu for game and I need to set all fields on same positions on every screen size
if screen will be big it must be scale everything on the layout and same on small screen size
like this:
can you provide some example for it?
The following is a list of resource directories in an application that provides different layout designs for different screen sizes and different bitmap drawables for medium, high, and extra high density screens.
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
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
This has been taken from http://developer.android.com/guide/practices/screens_support.html
If you sort your xml files this way, Android itself figures out what file to choose depending on the screen size of the device.
While designing the desired layout, you can opt for Relative Layout which usually sticks to its attributes such as alignParentBottom, alignParentTop, alignParentRight, alignParentLeft to name a few.
I hope this solves your issue, although I'm not clear what you're talking about when you say "coordinates system pt"
create the image with 9-patch so no need to save the images for different density like hdpi,mdpi etc. it will adjust with control as you define the size or you can save images with different size into the hdpi, mpdi with same name and by runtime in device it will get the appropriate images as per the density available
edit
links for 9-patch
http://developer.android.com/guide/developing/tools/draw9patch.html
http://android10.org/index.php/articlesother/279-draw-9-patch-tutorial
http://www.androiddom.com/2011/05/android-9-patch-image-tutorial.html

Testing Android application with different-sized screens

I have a question for you guys about multiple screens.
I am testing an Android application for different-sized screens using emulator. The application have been initially developed for resolution 320*480. I know it is not good and I have problems in my code. Moreover, I have used pixels in some places of code instead of dip. You see, I am not a professional in Android. In any case, there is no problem for devices with resolution 320*480 and 480*800. For the second one the application looks stretched. According to documentation it should be so. But, when I am trying resolutions 540*960 or 1024*600 the application occupies just a part of screen and it seems to be 320*480. The question is: why it didn't stretched the application to the whole screen? How can I do it?
I have read Supporting Multiple Screens guide here: http://developer.android.com/guide/practices/screens_support.html#dips-pels, but I haven't found an answer for my question.
Have you go through this lines in the link given by you?
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 i
res/layout-xlarge-land/my_layout.xml // layout for extra large in landscape orientation
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
for different size devices, make different folder as given above like layout-small,layout-large.. and put your designing xml in that.
Hope this help you.

Categories

Resources