Question

This DP measure is pretty confusing, I'm trying to learn when should I use wrap_content and when should I set the height, when using ImageView.

My current issue is that I'm using wrap content on 3 images (and yes I have different resources for each screen size: mdpi,hdpi,xhdpi) BUT in some devices (both hdpi) since they have different width pixel size (480px for one and 590px for the other), in the 480px one, one of the images looks smaller cause their size is calculated cause of the wrap_content.

I could make my designer re-make all the images for the hdpi size, but I want to know when to use wrap_content and when to set DP size myself.

Was it helpful?

Solution

DP is just a unit of measure that normalizes for different screen pixel densities, which means a value like 50dp always has the same physical size no matter what device you run your app on.

As far as actually designing your layouts, you should almost always use either wrap_content or match_parent instead of setting hard numbers for width and height. Exceptions usually come about when you use layout_weight for children of a LinearLayout for doing proportional sizes, or when using the various layout anchors for children of a RelativeLayout.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top