共享元素转换后,Gif没有播放。滑行v 4.8.0

时间:2019-05-04 08:14:44

标签: android kotlin android-animation android-transitions

Gif正在列表中播放。 但是在共享元素过渡后,它停止了。

.diskCacheStrategy(DiskCacheStrategy.ALL)
 GlideApp.with(this)
                .load(arguments?.getString(EXTRA_IMAGE_URL))
                .onlyRetrieveFromCache(true)
                .listener(object : RequestListener<Drawable> {
                    override fun onLoadFailed(e: GlideException?, model: Any?, target: Target<Drawable>?, isFirstResource: Boolean): Boolean {
                        startPostponedEnterTransition()
                        return false
                    }

                    override fun onResourceReady(resource: Drawable?, model: Any?, target: Target<Drawable>?, dataSource: DataSource?, isFirstResource: Boolean): Boolean {
                        startPostponedEnterTransition()
                        return false
                    }
                })
                .into(view.ivDialog)

3 个答案:

答案 0 :(得分:0)

如果您所有的图像都是 Gifs ,则只需添加.asGif并用GifDrawable替换您的 listener

GlideApp.with(this)
                .load(arguments?.getString(EXTRA_IMAGE_URL))
                .asGif()
                .onlyRetrieveFromCache(true)
                .listener(object : RequestListener<GifDrawable> {
                    override fun onLoadFailed(e: GlideException?, model: Any?, target: Target<GifDrawable>?, isFirstResource: Boolean): Boolean {
                        startPostponedEnterTransition()
                        return false
                    }

                    override fun onResourceReady(resource: GifDrawable?, model: Any?, target: Target<GifDrawable>?, dataSource: DataSource?, isFirstResource: Boolean): Boolean {
                        startPostponedEnterTransition()
                        return false
                    }
                })
                .into(view.ivDialog)

您就可以出发了!

答案 1 :(得分:0)

在我的情况下有效的丑陋的hack(对不起,Java):

.listener(new RequestListener<Drawable>() {
        @Override
        public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<Drawable> target, boolean isFirstResource) {
          return false;
        }

        @Override
        public boolean onResourceReady(Drawable resource, Object model, Target<Drawable> target, DataSource dataSource, boolean isFirstResource) {
          if (resource instanceof GifDrawable){
            final Handler handler = new Handler();                
            handler.post(() -> resource.setVisible(true, true));
          }
          return false;
        }
      });

答案 2 :(得分:0)

看起来这是库中的一个问题,我们将不得不使用我们自定义的修复程序。就我而言,在不给用户造成任何障碍的情况下,我以一定的延迟重新加载了gif,以使其无缝运行。 (无论如何,图片将是第一次被缓存,Glide会有效地处理后续调用)

imageView.loadImageIfAvailable(logoUrl)
imageView.transitionName = imageTransitionName
                handler = Handler()
                runnable = Runnable {
                    imageView.loadImageIfAvailable(logoUrl)
                } 
                handler.postDelayed(runnable, 2000)

loadImageIfAvailable是我自己的扩展功能,可以使用Glide加载图像。

fun ImageView.loadImageIfAvailable(url: String?) {
    url?.let {
        Glide.with(context)
            .load(url)
            .into(this)
    }
}


Note: Don't forget to unregister the handlers by calling removeCallbacks on onStop()    
override fun onStop() {
    super.onStop()
    handler?.removeCallbacks(runnable)
}