21
What’s the difference between px
, dp
, dip
and sp
on Android?
21
What’s the difference between px
, dp
, dip
and sp
on Android?
27
DEFINITION: Corresponding to the number of pixels on the screen USE: avoid using px for everything, only in very specific cases is recommended.
DEFINITION: (Scale-Independent Pixels) Idem to dp, but also considers the size of the font the user is using. It is recommended to use this unit when specifying the size of a font, so that it is automatically adjusted according to the preferences of the user screen. USE: Always use sp for fonts!
DEFINITION: (Density-Independent Pixels) This unit is relative to the screen resolution. For example if the screen resolution is 160 dpi, it means that one dp represents 1 pixel in a total of 160. USE: I advise instead of using px always use dp.
We still have other units of measures used by Android
DEFINITION: Based on the physical size of the screen
DEFINITION: Based on the physical size of the screen
DEFINITION: 1/72 of an inch, based on the physical size of the screen
More about units of measurements and dimensions on Android here A super explanatory video created by @Netomarin http://www.youtube.com/watch?v=Ocaq1bu3f2w
4
Where to use:
sp
: for the definition of sources; dip
for other size definitions.
dip == dp
In accordance with Android API Guides:
160dpi
(points per inch) of screen, where 1dp
is approximately equal to 1px
. When executed on a higher density screen, the number of pixels used to draw 1dp
is scaled by an appropriate screen factor. Similarly, when on a lower density screen, the number of pixels used to 1dp
is reduced. The proportion of dp
to pixel change with the density of the screen, but not necessarily in direct proportion. Using units dp
(instead of pixel drives) is a simple solution for creating views in his layout capable of resizing properly for different screen densities. In other words, it provides consistency to the actual sizes of your user interface elements on different devices.dp
, but it is also scaled by the font size the user’s preference. It is recommended to use this unit when specifying font sizes, so it will be adjusted for both screen density and user preference.In addition to those described in the question, there are still other units of measure on Android:
The following image helps to describe this relationship between the Android units of measures:
Response based and translated that of Soen;
Browser other questions tagged android terminology unit-of-measurement
You are not signed in. Login or sign up in order to post.
Vlw! Broke a branch!
– McQuade
Good the answer, just adding that 1 dp = 1 px on mdpi screens, so it is easier for you to design your screens. A guide to this can be found at: http://developer.android.com/guide/practices/screens_support.html
– Neto Marin
Detail: some of this information has if you press Ctrl + Space on the property and read on the right in the box that opens with information. as well as for other things
– Paulo Roberto Rosa
Density-Independent pixel is the Google version for pixel replacement, that in the case of mobile devices is a point of such size that if it is seen at a distance that the person holds an appliance, merges with the surrounding points resulting in a continuous visual experience, without distinction between one point and another. The choice of 160 pixels per inch for average density (
mdpi
) is not arbitrary: it is the density at which a pixel on the screen has the approximate size of a pixel replacement.– Piovezan