Take the 2-minute tour ×

I've done absolute positioning on Android via density independent pixels and it works great on all the available emulator profiles. However, the Samsung Galaxy Tab has a density of 240 (like WVGA devices), but a much larger resolution: 1024x600. As a result, the positioning is off.

Are there other devices where density and resolution don't seem to fit together? How should I tackle these issues? It basically means I can't use density independent pixels, doesn't it?

share|improve this question
add comment

2 Answers

up vote 4 down vote accepted


Density and resolution have no relationship whatsoever and never have. Hence, they either never or always "fit together", depending on how you wish to use that phrase.

How should I tackle these issues?

Considering that you did not really describe any "issues", that is impossible to answer.


Density-independent pixels are not supposed to work with absolute positioning, because absolute positioning is defined as "positioning based on hardware pixels". In general, absolute positioning is to be avoided wherever possible. Density-independent pixels, for their intended uses (e.g., whitespace between adjacent widgets via margins), are just fine.

share|improve this answer
I'm making a game and I draw location markers on specific spots on a map screen. I don't think there's a reasonable alternative to absolute positioning for that. The issues I was referring to are that the positioning is off on the Galaxy Tab. –  futlib Feb 20 '11 at 16:46
There are many devices where resolution is not an aspect ratio preserving scaling of a G1 screen. The Motorola Droid is 480x854 and many other HDPI screens are 480x800. This is at the core of why AbsoluteLayout is deprecated - density and resolution are not necessarily linked. Do not use absolute positioning. Use smarter layouts that can handle these cases instead. –  adamp Feb 20 '11 at 16:49
Posted before your comment loaded. If you are aligning markers with an underlying map, I assume you are scaling the map to full screen? If so, you will need to determine that scaling and apply it to your marker coordinates instead of trying to use dips to perform the scaling. –  adamp Feb 20 '11 at 16:52
It's a bit more complicated actually, I'm using an ImageView with android:scaleType="centerCrop" as background. But you're saying I'd best calculate positions myself then? –  futlib Feb 20 '11 at 19:13
add comment

You shouldn't use absolute positions. You should use RelativeLayout.

share|improve this answer
See my comments to the answer by CommonsWare - I need to position markers on an image for a game, no alternative to absolute positioning there. –  futlib Feb 21 '11 at 16:09
add comment

Your Answer


