3

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.

Christopher Francisco
  • 15,672
  • 28
  • 94
  • 206
  • 1
    I don't know how to answer your question, actually is the same as mine. What I do to avoid this issue of different sizes is use different resources as you said, and set width and height as the same of the mdpi resource, this way it works fine in different screen sizes. – Victor Laerte Jun 04 '13 at 20:03
  • So it would be best for me to design based on mdpi and then just multiply each image size for 1.75 and 2.00? if yes, that would be... 320 x 480 canvas size on photoshop? – Christopher Francisco Jun 04 '13 at 21:00

1 Answers1

2

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.

Karakuri
  • 38,365
  • 12
  • 84
  • 104
  • What about when the images are fetched from URL, I suppose in that case I would have to set the width and height myself in DPs, right? – Christopher Francisco Jun 04 '13 at 20:35
  • You could; I tend not to like such solutions myself, but it depends on your needs. If your concern is the image being scaled, you can set a scale type on the ImageView, or possibly extend ImageView and try to handle those issues yourself. – Karakuri Jun 04 '13 at 20:47
  • My usual concern is not the scale type, but the actual proportion of the image, so it wont cover the whole screen on mdpi and be too small on xhdpi; and since they are fetched from an URL, I can't really have 1 image for each screen density – Christopher Francisco Jun 04 '13 at 20:59