Sign in to follow this  
sheep19

[android 2.2] UI is different on emulator than on a device

Recommended Posts

sheep19    494
I have started android development recently. Today I made a simple UI menu with some buttons and a text label.

However on the emulator is a bit different than on an actual android device (HTC Desire HD). To be specific, the buttons on the mobile device appear a bit more upwards than on the emulator.
Why is that? Is that expected from the emulator or does this imply that my UI will be different (from the current tested phone) on other phones?

[i]I have used dp for the positions for the buttons and sp for their text size like[/i] [i]suggested on android developer website.[/i]

Share this post


Link to post
Share on other sites
frob    44904
The manufacturers are able to customize the system for their device. Many of them will swap out system buttons, the system keyboard, and other elements.

Share this post


Link to post
Share on other sites
Don Carnage    648
How did you configure your emulator? Quick googling suggested an optimal configuration for Desire HD (below). Did you use those?

http://stackoverflow.com/questions/6149748/htc-desire-hd-android-sdk

http://stackoverflow.com/questions/5703124/the-correct-eclipse-android-device-configuration-for-htc-desire

Share this post


Link to post
Share on other sites
sheep19    494
Thank you for your answers.

I read an article on android developers website. It stated that I should use [b]dp[/b] and [b]sp [/b]so that UI will look the same on all devices with different screens. That's what I did, and here's the result:
[b]
Left side: HTC Desire HD
Right side: HTC Wildfire[/b]

[img]http://i44.tinypic.com/11sidk3.jpg[/img]

Why is that?

Share this post


Link to post
Share on other sites
frob    44904
You are working with the system in a "Please do the layout for me" mode. This is great for text-based stuff that uses minimal graphics.

Consider that the two have physically different screen ratios.

One is 800x480, or 5:3.
One is 320x240, or 4:3.

The platform is really good at scaling, stretching, and otherwise manipulating the screen to fit various devices.

If you have text it will make the text big enough to read on the huge tablets, or small enough to fit on the small phones. It will keep it centered and give a generally pleasant layout across a huge variety of devices.

That is great for anything that mostly uses text, or has minimal use of pixel-perfect graphics. It will work great for simple line drawings and graphs and other general use graphics.



But many games want pixel-perfect alignment. Resizing, scaling, and otherwise manipulating layout in such games can be detrimental.

Many games will tweak their UI code to specifically support the more common screen ratios of 4:3, 5:3, 16:9, and 16:10. They will also often normalize their view rectangle so it exists from 0.0 to 1.0, or from -1.0 to 1.0, so that it accommodates large and small displays, and can be easily extended to new form factors.

Share this post


Link to post
Share on other sites
robobrain    106
[quote name='sheep19' timestamp='1323703565' post='4893128']
Thank you for your answers.

I read an article on android developers website. It stated that I should use [b]dp[/b] and [b]sp [/b]so that UI will look the same on all devices with different screens. That's what I did, and here's the result:
[b]
[/b][/quote]

dp and sp really only work with text sizes, buttons, etc. Things that can have a discreet size assigned to them. keep in mind that dp and sp will mean that the interface elements look the same size on any screen. It does not mean they will be scaled proportionally. in other words, 160 dp on a 160dpi screen will equal 160pixels, but on a 72dpi screen it will equal 72pixels. Android only makes sure that they both measure out to about an inch in the real world.

The only way to make sure it looks good, in vanilla Android, is to design different layouts for different screen densities.

Share this post


Link to post
Share on other sites
JonBonazza    121
I highly recommend watching this video. The lead UI programmer from Square Inc. does a great job of covering just this and much more.
[url="http://www.youtube.com/watch?v=jF6Ad4GYjRU"]http://www.youtube.com/watch?v=jF6Ad4GYjRU[/url]

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this