Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Resize images with Glide in a ImageView Android

I have a lot of doubts about the treatment of the images in android, and I was hoping to see if you could solve them.

At this point I have an image that occupies 320 dp high, and match_parent width, which is around 60% of the screen. This image of the load with Glide, of some images in 1080 that I have personally.

I tried to make centroCrop and fitXY, but always deform the images. The first type I know cuts the image, but the second one fits a size, but it does deform the image high or wide.

Is there any way, to insert it with Glide and see it as it is? What properties have I to touch on ImageView and which of Glide?

<ImageView         android:id="@+id/img"         android:layout_width="match_parent"         android:layout_height="match_parent"         android:nestedScrollingEnabled="false"         app:layout_collapseMode="parallax"         android:scaleType="fitXY"         app:layout_scrollFlags="scroll|enterAlways" /> 
like image 565
Traif Avatar asked Sep 08 '17 10:09

Traif


People also ask

How do I change the height and width of a picture in Glide?

Add an explicit width or height to the ImageView by setting layout_width=500dp in the layout file. Call . override(width, height) during the Glide load and explicitly set a width or height for the image such as: GlideApp.

How do I reduce the size of a photo in Glide?

Option 1: Resizing image size with override(x, y) . 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.

What is Glide override?

Image Resizing with override(x, y) Glide automatically limits the size of the image it holds in cache and memory to the ImageView dimensions.


2 Answers

Override must be accessed via RequestOptions in the most recent version of Glide 4.x. You can add RequestOptions through apply()

Glide.with(context)     .load(path)     .apply(new RequestOptions().override(600, 200))     .into(imageViewResizeCenterCrop); 
like image 63
Bhuvanesh BS Avatar answered Oct 07 '22 17:10

Bhuvanesh BS


in glide 4.x 'override' is in 'apply' :

Glide.with(getBaseContext())  .load(path)  .apply(RequestOptions.placeholderOf(R.mipmap.no_wifi)  .error(R.mipmap.no_wifi)  .override(500,500))  .into(mImageView); 
like image 31
abbasalim Avatar answered Oct 07 '22 17:10

abbasalim