Specifying UI dimensions in Android

I am back with a very useful tip that will prevent us from lot of trouble, when it comes to UI elements size on different screen sizes and screen density.

In order to ensure that a graphic or text looks good in every Android device, despite of the varying parameters of a phone (screen size and density), a relative meter has to be used (rather than absolute). As such, use sp (space-independent pixels) for fonts size, which takes into account the user’s font size preference, and dp (dots per pixel) for anything else, like a graphic or border.

From Android SDK documentation (http://developer.android.com/guide/topics/resources/more-resources.html#Dimension):
You should use these units when specifying view dimensions in your layout, so the UI properly scales to render at the same actual size on different screens. (The compiler accepts both “dip” and “dp“, though “dp” is more consistent with “sp“.)

Take care of your code!

Advertisements

About sermojohn

Professional Software Engineer
This entry was posted in Android and tagged , , , , , , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s