Search code examples
androidandroid-layoutpixel-density

Android:Is it advisable to use dp to specify size of UI elements?


Is using dp alone good enough to ensure that the size of the UI elements will be consistent aross all screen sizes and densities? Or do we have to use Linear Layout's weightSum feature to ensure a more consistent result?


Solution

  • Yes.

    Depending on what you try to accomplish: dp will ensure the same size across screens, and weights (or percent in the android support library) will keep its ratios.

    • If you want 3 columns of the same width you use weights for an equal distribution
    • If you have an icon, or a button you use dp to ensure the same actual size on all devices