【问题标题】:Glide gif doesnt play滑行 gif 不播放
【发布时间】:2021-06-20 20:10:30
【问题描述】:

我想将 gif 加载到 imageview 中,它会显示但不会开始播放。我使用此代码:

Glide.with(context)
             .load("https://media.giphy.com/media/7rj2ZgttvgomY/giphy.gif")
             .into(imageView)

我也尝试添加.asGif(),但在这种情况下,图像根本不会显示。我正在使用滑翔 3.8.0

【问题讨论】:

    标签: android android-glide


    【解决方案1】:

    试试这个。

    Glide.with(context)
        .load(imageUrl)
        .asGif()
        .placeholder(R.drawable.loading2)
        .crossFade()
        .into(imageView);
    

    【讨论】:

      【解决方案2】:

      你也可以试试

      Glide  
          .with(context)
          .load(gifUrl)
          .asGif()
          .error(R.drawable.full_cake)
          .diskCacheStrategy(DiskCacheStrategy.SOURCE)`
          .into(imageViewGif);
      

      【讨论】:

        【解决方案3】:

        将您的 gif 更改为 https://i.giphy.com/media/7rj2ZgttvgomY/giphy.webp

        Glide.with(context)
        .load("https://i.giphy.com/media/7rj2ZgttvgomY/giphy.webp")
        .asGif().into(imageView);
        

        你也可以试试GIFView

        【讨论】:

          【解决方案4】:

          您可以参考:https://github.com/bumptech/glide/issues/1059

          如果没找到,可以换最新版的Gline

          repositories {
            mavenCentral()
            maven { url 'https://maven.google.com' }
          }
          
          dependencies {
            compile 'com.github.bumptech.glide:glide:4.2.0'
            annotationProcessor 'com.github.bumptech.glide:compiler:4.2.0'
          }
          

          希望你能找到解决办法。

          【讨论】:

            【解决方案5】:

            您的代码没有任何问题。您可以检查您是否拥有Internet 权限。

            <uses-permission android:name="android.permission.INTERNET" />
            

            您的网速可能很慢,Glide 可能会花费太多时间来加载,所以到那时您可以使用以下命令添加占位符图像:

            .placeholder(android.R.color.holo_green_dark)
            

            或者您可以使用

            Listner 添加到 Request
              .listener(new RequestListener<String, GlideDrawable>() {
                                @Override
                                public boolean onException(Exception e, String model, Target<GlideDrawable> target, boolean isFirstResource) {
                                    return false;
                                }
            
                                @Override
                                public boolean onResourceReady(GlideDrawable resource, String model, Target<GlideDrawable> target, boolean isFromMemoryCache, boolean isFirstResource) {
                                    return false;
                                }
                            })
            

            看看Exception是什么。

            【讨论】:

            • 也不例外
            • onResourceReady 被调用了吗?
            【解决方案6】:

            在我的例子中,我将 imageview 尺寸设置为 ma​​tch_parent 并在 dp 中指定它为我做了。

            不确定为什么完全 match_parent 在对话框中不起作用,播放 GIF,可能与缩放有关,如果是这种情况,那么使用 scaleType:fitXY 也应该起作用

            【讨论】:

              猜你喜欢
              • 1970-01-01
              • 1970-01-01
              • 1970-01-01
              • 2016-12-17
              • 2018-09-16
              • 2012-02-13
              • 2018-06-05
              • 2014-06-27
              • 1970-01-01
              相关资源
              最近更新 更多