Make image fit ImageView

4,888 views
Skip to first unread message

vi...@itamecodes.com

unread,
Apr 28, 2015, 11:29:41 AM4/28/15
to glidel...@googlegroups.com
Hi!
I am trying to do a transition animation when going from a grid view to the detail view and thanks to https://groups.google.com/d/topic/glidelibrary/iXIKV1MN0Sk/discussion , I was able to do it fine with override() like this:-

in the grid view adapter:-
Glide.with(c)
                .load(url).fitCenter()
                .override(500,758)
                .into(mMovieImageView); 

and in the detail view:-
Glide.with(getActivity().getApplicationContext())
                .load(url).fitCenter()
                .override(500, 758)
                .into(mMovieBackgroundImageView);

  • In the detail view , we have the image view dimensions as fill parent . But the image that gets displayed does not scale to the entire image view. 
  • If I set android:scaleType="fitXY" , then it seems glide does not load the image which is already preloaded and hence the transition animation gets broken .
  •  I tried increasing the dimensions in override to above 1000 , like override(1080,1636), but it still behaves the same .
Any help/pointers would be really helpful.
Message has been deleted

Róbert Papp

unread,
Apr 28, 2015, 1:18:13 PM4/28/15
to Vivek tamingcodes, glidel...@googlegroups.com
If you use fitCenter() the image will be resized, fitXY after that would stretch losing aspect ratio (is that what you want). Try using fitCenter as android:scaleType as well, as well as maybe android:adjustViewBounds, I always try that.

+Robi

--
You received this message because you are subscribed to the Google Groups "Glide" group.
To unsubscribe from this group and stop receiving emails from it, send an email to glidelibrary...@googlegroups.com.
To post to this group, send email to glidel...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/glidelibrary/880dd819-6d6e-4c54-80a0-b097d913f744%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

vi...@itamecodes.com

unread,
Apr 28, 2015, 1:20:11 PM4/28/15
to glidel...@googlegroups.com, vi...@itamecodes.com
I fixed it like this:-
Glide.with(getActivity().getApplicationContext())
                .load(url).fitCenter()
                .override(500, 758)
                .into(new SimpleTarget<GlideDrawable>() {
                    @Override
                    public void onResourceReady(GlideDrawable resource, GlideAnimation<? super GlideDrawable> glideAnimation) {
                        mBackground.setImageDrawable(resource);
                    }
                });
and I set android:scaletype="fitXY" on the image view.. worked perfect.

Róbert Papp

unread,
Apr 28, 2015, 1:20:29 PM4/28/15
to Vivek tamingcodes, glidel...@googlegroups.com
Also can try disabling the default crossFade() (from DrawableRequestBuilder's ctor) via dontAnimate().

+Robi

Róbert Papp

unread,
Apr 28, 2015, 1:26:39 PM4/28/15
to Vivek tamingcodes, glidel...@googlegroups.com
Glad it worked out, I think you should still try dontAnimate() I looked at the library code and that really seems the culprit (it delays setting the drawable). Whipping your own target can be error prone in the long run as you lose any fixes (hopefully none, but who knows) that are implemented in the GlideDrawableImageViewTarget hierarchy.

+Robi

--
You received this message because you are subscribed to the Google Groups "Glide" group.
To unsubscribe from this group and stop receiving emails from it, send an email to glidelibrary...@googlegroups.com.
To post to this group, send email to glidel...@googlegroups.com.

vi...@itamecodes.com

unread,
Apr 28, 2015, 1:28:10 PM4/28/15
to glidel...@googlegroups.com, vi...@itamecodes.com
Thanks Robert! Will try that


On Tuesday, April 28, 2015 at 10:29:41 AM UTC-5, vi...@itamecodes.com wrote:

amo...@gmail.com

unread,
Nov 29, 2015, 1:01:31 PM11/29/15
to Glide
Thanks .That worked.

tkhal...@gmail.com

unread,
Oct 4, 2017, 7:03:09 AM10/4/17
to Glide


Thanks Bro you saved my day!!!!

tkhal...@gmail.com

unread,
Oct 4, 2017, 7:26:05 AM10/4/17
to Glide

Dear Robert, 

I was using TouchImageView for zoom in zoom out functionality , but after implementing  


.into(new SimpleTarget<GlideDrawable>() {
                    @Override
                    public void onResourceReady(GlideDrawable resource, GlideAnimation<? super GlideDrawable> glideAnimation) {
                        mBackground.setImageDrawable(resource);
                    }
                });

My image is not zooming so please any suggestion/solution...i am also trying to full fill the imageview.

Regards: Tasawar
Reply all
Reply to author
Forward
0 new messages