I have some 100*100 icons and I cannot find better resolution icons so I put them inside drawable folder. The width and height of the image view are set to wrap_content. When the image is shown on a xhdpi screen will the image be scaled to 200*200 automatically? or should I create all sizes myself and place them in different folders? should I do that?
6 Answers
When you specify the width and height as wrap_content, then images won't be scaled and will occupy only the original size i.e will occupy 100x100 pixels even in xhdpi. This means, your image will look small on higher end device. If you don't want the image to appear small, you have to create all the sizes of the image and put it in various different density folders.

- 1,070
- 6
- 10
I'm not sure what are you trying to do, are you trying to have the imageview to adapt to your image's size or are you trying to have your image view at a fixed size?
When the image is shown on a xhdpi screen will the image be scaled to 200*200 automatically?
Nope, it will still display at 100*100px (around 50dp, as xhdpi's multiplier is 2.0)
or should I create all sizes myself and place them in different folders? should I do that?
Definitely do this, there are a lot of tools out there to help you do this. One example is http://romannurik.github.io/AndroidAssetStudio/index.html

- 692
- 5
- 8
In my case I will do a simple Math. Here is a sample reference taken from the docs.
This method will re-size your Image, Our example argument will be Resource Image
public static Bitmap decodeSampledBitmapFromResource(Resources res, int resId,
int reqWidth, int reqHeight) {
// First decode with inJustDecodeBounds=true to check dimensions
final BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
BitmapFactory.decodeResource(res, resId, options);
// Calculate inSampleSize
options.inSampleSize = calculateInSampleSize(options, reqWidth, reqHeight);
// Decode bitmap with inSampleSize set
options.inJustDecodeBounds = false;
return BitmapFactory.decodeResource(res, resId, options);
}
This is a helper method for re-sizing Image
public static int calculateInSampleSize(
BitmapFactory.Options options, int reqWidth, int reqHeight) {
// Raw height and width of image
final int height = options.outHeight;
final int width = options.outWidth;
int inSampleSize = 1;
if (height > reqHeight || width > reqWidth) {
final int halfHeight = height / 2;
final int halfWidth = width / 2;
// Calculate the largest inSampleSize value that is a power of 2 and keeps both
// height and width larger than the requested height and width.
while ((halfHeight / inSampleSize) > reqHeight
&& (halfWidth / inSampleSize) > reqWidth) {
inSampleSize *= 2;
}
}
return inSampleSize;
}
UPDATE
Basically it wont automatically scale to 200*200, you need to do it by yourself. The code above I provide will let you change your image size programatically, other alternative around is to use folder with DPI as you've mention.

- 1,642
- 2
- 20
- 26
You can add attributes to your imageview like:-
android:scaleType="fitXY"
Also if you are using table layout for your imageview its better to take width="0dp" because table layout acts different.. you might also have to add weight = "1" ..

- 539
- 4
- 20
Please go through below link and read: How android system resize the drawable for different screen size.
Different image sizes for resolution-specific Drawable folders
and
http://developer.android.com/guide/practices/screens_support.html

- 1
- 1

- 1,765
- 15
- 20