Monday, May 28, 2012

[android-developers] Re: reduce size of a screen

On Sunday, 27 May 2012 08:31:01 UTC+1, baturanija1 wrote:
Hej people,i am making an application wich screen has a good dimension
for my phone-HTC DESIRE .there are othes phones who has smaller or
bigger screen...so i am asking is there an option to makk app to
automaticly reduce a size of a screen for all size of telefon screen?
Thanks for reading :)

The HTC Desire is my main dev target for games.  What I've done/found (this is very hand-coded):

Using a SurfaceView for output.  I develop all my art assets for 800x480 (Desire native).

When the app starts it works out the aspect ratio of the phone's screen, and then works out what the equivalent Desire res, depending on the orientation I want.  For example, if I want Landscape: I take the phone's physical short axis in pixels and work out it's ratio to the desire's 480.  I then multiply that by the phone's physical long axis: I now know I'm rendering to something N x 480 pixels.  Theoretically I then render to a bitmap that size every loop, then blit that to the screen, scaling to the physical screen size.

Here's where it gets tricky:

If the screen is larger than the Desire's, you need to blit it with anti-aliasing on in order to make it look good (this isn't hard, you just need to know to do it).

If the screen is smaller than the Desire's you're probably gonna run into trouble:  the available heap scales on a per phone basis depending on the screen's resolution.  If you are storing all your bitmaps at 800x480, but are on a phone that is only 320x240, then you are probably going to run out of memory and crash.  Therefor, on startup, you check if the physical screen is smaller than your target render, and if it is you scale down your internal bitmaps, and you scale down all your assets as you load them.  So instead of rendering to an N x 480 bitmap then blitting it to the SurfaceView, you render to an N x 240 (in this example) bitmap and blit it.  On smaller screens you don't need anti-aliasing: you are down-sampling so it should be fairly good without it.

Examples:

ARCHOS 101 tablet, 1024x600 resolution:
scaling the 600 to 480, this gives 819x480.  I load all my assets normally and render to an output that size, then blit that to the screen, scaling up with anti-aliasing turned on.

HTC Wildfire, 320x240 resolution:
240 / 480 = 0.5: when I load all my graphics assets I scale them down to half size.  I render to a bitmap that's 320x240 in size and blit it to screen without antialiasing.

That's the simple approach.  On top of that you have to work out how you handle aspect ratio changes: do you just scale and thus skew the output, or do you render more stuff on widescreen and chop the edges off for 4:3. 

Using this method you only need one set of art assets (as opposed to the normal Android way of including different versions for different pixel-densities).  As such, it will basically look less-good the further the screen it's running on is from the target screen (800x480), but in my experience it is well within acceptable bounds, and the pros outweigh the cons (ease of development, unbloated .apk size). 

Note that this is for game development, using fullscreen and rendering everything by hand.  If you were using the Android UI normally I doubt it would be as good a technique.

Iain

--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate