I want to make an image fit into my image view
. I am loading the image programmatically using Glide. It does load the image but does not stretch it to fit my entire image view
. It leaves blank spaces on both sides like this
I want to display my entire image without cropping so I can't use
android:scaleType="centerCrop"
There's a way to fit the entire image into my image view
by using
android:background="@drawable/image"
It stretches my image to fit the entire image view
. But how can I achieve the same if i am loading the image using Glide ?
With Glide, if the image should not be automatically fitted to the ImageView , call override(horizontalSize, verticalSize) . This will resize the image before displaying it in the ImageView .
centerCrop() is a cropping technique that scales the image so that it fills the requested bounds of the ImageView and then crops the extra. The ImageView will be filled completely, but the entire image might not be displayed. RequestOptions myOptions = new RequestOptions() . centerCrop(); Glide.
Glide is an Image Loader Library for Android developed by bumptech and is a library that is recommended by Google. It has been used in many Google open source projects including Google I/O 2014 official application. It provides animated GIF support and handles image loading/caching.
I finally got the answer to it. Simply use
android:scaleType="fitXY"
in the xml ImageView tag like this and load image using Glide or BitmapFactory without using any scaleType attribute there.
<ImageView
android:id="@+id/image_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="fitXY"/>
Load Image to the image View
Glide.with(this).load(imageUrl).into((ImageView)findViewById(R.id.image_view));
You can use centerCrop method.
Glide.with(context).load(url).centerCrop().placeholder(R.drawable.default_image).into(img);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With