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

Started by
5 comments, last by JonBonazza 12 years, 4 months ago
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 have used dp for the positions for the buttons and sp for their text size like suggested on android developer website.
Advertisement
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.
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
It is I, the spectaculous Don Karnage! My bloodthirsty horde is on an intercept course with you. We will be shooting you and looting you in precisely... Ten minutes. Felicitations!
Thank you for your answers.

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

Left side: HTC Desire HD
Right side: HTC Wildfire


11sidk3.jpg

Why is that?
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.

Thank you for your answers.

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



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.
Want to make Android Games?
Then check out the free RoboBrain SDK.
[size="2"][url="http://www.robobrain.org"]www.robobrain.org[/url]
I highly recommend watching this video. The lead UI programmer from Square Inc. does a great job of covering just this and much more.
Co-founder/Lead Programmer
Bonafide Software, L.L.C.
Fairmont, WV 26554 US

This topic is closed to new replies.

Advertisement