I wan't to insert in my SimpleDraweeView with
android:layout_width="50dp"
android:layout_height=50dp
some picture, that may be bigger than this dimensions. I want to resize picture proportionally, so for example picture with source dimension 117x81 should show like 50x34. What should I do to that the picture is not circumcised, but decreased proportionally.
You should set actualImageScaleType in you xml and choose centerInside option. Do not use android:scaleType since it does not have effect on Drawee.
Please take a look at other available options as well.
Reference link: Fresco Drawee Scaling
You can doing that with is code:
simpleDraweeView.getHierarchy().setActualImageScaleType(ScalingUtils.ScaleType.CENTER_CROP);
Related
I am setting a imgage in an ImageView. I want to scale down the image size without reducing the imageview size. Please guide me step by step.
Use scaleType parameter for your imageviews and set the value to centerFit or centerCrop. More here: http://developer.android.com/reference/android/widget/ImageView.ScaleType.html
Taken from this link: source
You should also see android:adjustViewBounds to make the ImageView resize itself to fit the rescaled image. For example, if you have a rectangular image in what would normally be a square ImageView, adjustViewBounds=true will make it resize the ImageView to be rectangular as well. This then affects how other Views are laid out around the ImageView.
What i need is that image should be scaled till it retains the exact proportions after that it should not be scaled further, so that every time width is equal to height of the image view.
As if don't scale properly it will get out of shape, and i need it to be in 1:1 ratio of width and height.
Will
Imageview:scale="fitxy"
work in this case ?
Please help thnk you.
I am working on android ICS
To keep aspect ratio, you should make the image the src rather than background.
Take a look at the ScaleType documentation here http://developer.android.com/reference/android/widget/ImageView.ScaleType.html.
You should try using either android:scaleType="centerInside" or android:scaleType="centerCrop".
Hope that helps!
android:scaleType="fitXY"
Fits the screen size of the device.
Try this adding this
android:layout_height="150dp" //or your designed proportion
android:layout_width="150dp" //or your designed proportion
android:scaleType="fitXY"
In my code I want to set a default image for my imageview. All my images are of 174px X 174px. So, I want the default image to be same size. This is my xml for image view
//....code
<ImageView
android:id="#+id/ivCover"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:contentDescription="Default Image"
android:src="#drawable/default_cover" />
//....some other code
Now, my default_cover.jpg is also 174px X 174px. But it shows a smaller image. I've tried all
android:scaleType="centerInside"
android:scaleType="center"
android:scaleType="matrix"
even when most of them were senseless for me but still I tried all of 'em & none of them works. Then I specified the height & width of image by specifying
android:layout_width="174px"
android:layout_height="174px"
(I know using dp is better than px but because this image size is fixed & I was just testing it). So it shows
[default image]
while when loaded from an external url using
Bitmap bitmap = BitmapFactory.decodeStream((InputStream) new URL(url_source_for_image).getContent());
ivCover.setImageBitmap(bitmap);
desired image
[]
The two pictures may not look very different here but the difference is very clear on my android device. And please don't say that I didn't try other solutions..
Here is a list of links of so itself..
ImageView fit without stretching the image
Fit image into ImageView, keep aspect ratio and then resize ImageView to image dimensions?
ImageView one dimension to fit free space and second evaluate to keep aspect ration
Resizing ImageView to fit to aspect ratio
Maximum width and height for ImageView in Android
Image in ImageView is stretched - Android
Android: How to prevent image from being scaled in ImageView or ImageButton?
Sounds like the answer is to use drawable-nodpi. For future reference, if you have the same named image in both the ldpi/hdpi/etc and in no-dpi, I think the no-dpi one will be ignored.
I will be displaying an image in an ImageView that will always be much higher and wider than the size of the screen. Is there a simple way to scale the image down so that it fills the ImageView exactly?
Try setting up the scale type in the xml, i believe it scaleXY is the one you are looking for scale types
<ImageView
android:scaleType="scaleXY"
android:src="#drawable/my_image"/>
If you're loading the view in XML, the android:scaleType parameter should do the trick.
http://developer.android.com/reference/android/widget/ImageView.html#attr_android:scaleType
I am a puzzled about using src or background for an ImageView.
I know the former means the content of this ImageView and the latter means the background of the ImageView.
But how to decide which one to use? I don't see the difference.
All views can take a background image.
The src to an ImageView has additional features:
different scaling types
adjustViewBounds for setting bounds to match image dimensions
some transformations such as alpha-setting
And more that you may find in the docs.
when you use android:background, image will be set to fit on ImageView area(i.e according to width and height of ImageView). It doesn't matter if the image is smaller or larger than ImageView.
when you use android:src, then image will display in its original size. No
automatic scaling, adjustments will happen.
Note: Using android:src, we can get additional benefit of adjustViewBounds property
If you set an image to be the background of your ImageView, then the image will scale to whatever size the ImageView is. Other than that, src is a foreground image and background is a background image. Pretty much as it implies.
The difference between XML attribute src and background in ImageView:
The background will stretch according to the length given by the ImageView component, and SRC will hold the size of the original image without stretching. SRC is the picture content (foreground), BG is the background, can be used at the same time.
In addition: ScaleType only works on SRC; BG can set transparency, for example, in ImageButton, you can use Android:scaletype to control how the image is scaled, sample code as follows:
<ImageView
android:id="#+id/img"
android:layout_height="60dip"
android:layout_width= "60dip"
android:src="#drawable/logo"
android:scaleType="centerInside"
android:layout_centerVertical= "true"/>
Feel free to ask doubt if you get any.