Reputation: 1107
I am writing an application on android. I am downloading an image from the server and trying to set it as an ImageView background using setBackgroundDrawable.
Drawable drawable = Drawable.createFromPath(path)
imageView.setBackgroundDrawable(drawable);
It works but the image is resized (it is getting smaller). Does anyone have an idea about how to set an image view background without changing its size?
Edit: I solved the problem by using:
File imgFile = new File(path);
Bitmap myBitmap = BitmapFactory.decodeFile(imgFile.getAbsolutePath());
imageView.setImageBitmap(myBitmap);
Upvotes: 3
Views: 2548
Reputation: 4908
Use these two properties:
android:scaleType
android:adjustViewBounds
Study about them in : ImageView
Upvotes: 1
Reputation: 5584
imageView.setScaleType (ImageView.ScaleType.MATRIX)
Set image scale type to Matrix it will scale using the image matrix when drawing.
Upvotes: 2