Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Avoid using 'px' as units, use 'dp' instead

Tags:

android

alert

Why did I have this Alert message in my xml layouts in android

the message is Avoid using "px" as unite, use "dp" instead

like image 210
RiadSaadi Avatar asked Dec 06 '13 16:12

RiadSaadi


3 Answers

The answer is right there: What is the difference between "px", "dp", "dip" and "sp" on Android?

pixels is the exact number, and dip is dynamic: better to keep the view you want on any type of screen

like image 165
Charline Avatar answered Sep 28 '22 09:09

Charline


It's a best practices thing.

dp = Density-independent pixel

A pixel is not a pixel is not a pixel. Some screens have 72 pixels per inch some have 200+

Read more here: http://developer.android.com/guide/practices/screens_support.html

like image 33
Lenny Avatar answered Sep 28 '22 10:09

Lenny


DP should always be used as the layout will better scale for devices that have lower/higher DPIs. If you use px for the layout its a fixed will use this many pixels, therefore the layout component could either be really small or massive and not look good.

dp should always be used as it handles the scaling for various devices much better.

Check http://developer.android.com/guide/practices/screens_support.html for more info.

like image 25
Boardy Avatar answered Sep 28 '22 11:09

Boardy