Resize images with Glide in a ImageView Android

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP



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" />



Thanks in advance.





Use .override(w,h) for it.
– Piyush
Sep 8 '17 at 10:41


.override(w,h)





And I have a image with no 1080? For example with an user. They have images with diferents sizes.
– Traif
Sep 8 '17 at 10:51





@Traif check custom transformation with Glide.
– Raghunandan
Sep 8 '17 at 10:56





Not understand.. what is your problem if you override(w,h)??
– Ranjith Kumar
Sep 8 '17 at 11:03




5 Answers
5



Override must be accessed via RequestOptions in the most recent version of Glide.


Override


RequestOptions


Glide


Glide
.with(context)
.load(path)
.apply(new RequestOptions().override(600, 200))
.into(imageViewResizeCenterCrop);


Glide
.with(context)
.load(path)
.override(600, 200)
.centerCrop()
.into(imageViewResizeCenterCrop);



@Raghunandan is right.you should try transformation your own way.





Note: Override must be accessed via RequestOptions in the most recent version of glide: "apply(new RequestOptions().override(600, 200))"
– Elletlar
Apr 24 at 16:19



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);



If you want to load image without using glide then you can use scaleType "fitCenter" or "centerInside" as follows -


<ImageView
android:id="@+id/img"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:nestedScrollingEnabled="false"
app:layout_collapseMode="parallax"
android:scaleType="centerInside"
app:layout_scrollFlags="scroll|enterAlways" />



With Glide you can use override(w,h). When you use override(w,h), glide generates a new bitmap with width and height mentioned in override(w,h) and then load the image into ImageView. You can use fitCenter() to align the image. You can also use diskCacheStrategy(). If you don't use it, Glide will catch only newly generated bitmap. If you want to catch original image also then use diskCacheStrategy(DiskCacheStrategy.ALL).


Glide.with(context)
.load(image_path)
.override(800, 400)
.fitCenter()
.diskCacheStrategy(DiskCacheStrategy.ALL)
.into(imageView)



I hope this helps.





Note: Override must be accessed via RequestOptions in the most recent version of Glide: "apply(new RequestOptions().override(800, 400))"
– Elletlar
Apr 24 at 16:18



you have to do the following with your imageview :


<ImageView
android:id="@+id/img"
android:layout_width="match_parent"
android:layout_height="200dp"
android:scaleType="fitCenter" />



and this with your glide :


Glide.with(getBaseContext())
.load(path)
//.placeholder(R.drawable.drawable)
.error(R.drawable.noimg)
.animate(R.anim.animation_fade_in)
.into(mImageView);



This works perfectly with me .






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Firebase Auth - with Email and Password - Check user already registered

Dynamically update html content plain JS

Creating a leaderboard in HTML/JS