Android Glide library not working with shared element transitions

前端 未结 2 432
青春惊慌失措
青春惊慌失措 2020-12-06 17:38

I\'m looking to adopt the Glide library in place of Universal Image Loader but I\'m running into a problem with regards to shared element transitions.

In my simple S

2条回答
  •  太阳男子
    2020-12-06 18:00

    For those of you that are struggling with the SharedElementTransition using Glide I think I got a workaround that works, or at least it worked for me. In your second activity or fragment use this code:

    postponeEnterTransition();
    GlideApp.with(this)
            .load(imageToLoad)
            .listener(new RequestListener() {
                @Override
                public boolean onLoadFailed(@Nullable GlideException e, Object model, Target target, boolean isFirstResource) {
                    return false;
                }
    
                @Override
                public boolean onResourceReady(Drawable resource, Object model, Target target, DataSource dataSource, boolean isFirstResource) {
                    startPostponedEnterTransition();
                    return false;
                }
            })
            .into(imageView);
    

    If you are targeting API<21 use:

    supportPostponeEnterTransition();
    supportStartPostponedEnterTransition();
    

    Hope that helps!

提交回复
热议问题