I wand to handle the multiple screen handling in my app.
I see that in tutorials margin and padding are set in the dp.
I want to know if dp is the best unit for padding and margin? What other units are available for setting padding and margin?
I wand to handle the multiple screen handling in my app.
I see that in tutorials margin and padding are set in the dp.
I want to know if dp is the best unit for padding and margin? What other units are available for setting padding and margin?
In my opinion, using dp is the best choice for margin and padding.
The units available are:
dp Density-independent Pixels - an abstract unit that is based on the physical density of the screen. These units are relative to a 160 dpi screen, so one dp is one pixel on a 160 dpi screen. The ratio of dp-to-pixel will change with the screen density, but not necessarily in direct proportion. Note: The compiler accepts both "dip" and "dp", though "dp" is more consistent with "sp".
sp Scale-independent Pixels - this is like the dp unit, but it is also scaled by the user's font size preference. It is recommend you use this unit when specifying font sizes, so they will be adjusted for both the screen density and user's preference.
mm Millimeters - based on the physical size of the screen.
dp stands for density independent pixels. It works best on wider ranges of screens and different densities out there. It automatically scales based on the device its been on
The frequent units in android are sp and dp.
sp stands for scale-independent pixels.
dp or dip stands for density-independent pixels.
there is no difference between the two.They both have 160 units per square inch, they are both density independent, and neither have the same physical size on different screens.
when should you use sp and when you should you use dp?
Use sp for text size, because but it is scaled by the user’s font size preference.
Use dp for everything else.