Lew Wei Hao
Lew Wei Hao

Reputation: 843

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?

Upvotes: 2

Views: 177

Answers (2)

Yes it is. If you want to have same look and feel on different screen resolutions . it is a relative measure hence it calculates how much pixels to take on different screens whereas pixels are absolute. For consistent Ui and user experience its recommended.

Upvotes: 2

David Medenjak
David Medenjak

Reputation: 34522

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

Upvotes: 3

Related Questions