android - 如何从 url 在 android 中播放 gif?

标签 android animated-gif

我想在 imgur 应用程序等 android 应用程序中从 url 播放动画 gif。 Imagur 非常棒而且非常快。我正在使用 webview 加载 gif,但它不符合要求。

最佳答案

您可以使用 GlideImageView 上播放 gif。所以,让我们将它添加到您应用的 gradle 中:

repositories {
    mavenCentral()
}

dependencies {
    compile 'com.github.bumptech.glide:glide:3.6.1'
    compile 'com.android.support:support-v4:23.1.1'
}

然后,创建一个ImageView:

<ImageView
    android:id="@+id/imageView"
    android:contentDescription="@string/content"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"/>

在您的 Activity 中:

Glide  
    .with(context) // replace with 'this' if it's in activity
    .load("http://www.google.com/.../image.gif")
    .asGif()
    .error(R.drawable.error_image) // show error drawable if the image is not a gif
    .into(R.id.imageView);

欲了解更多信息,请打开此帖子 Glide — Displaying Gifs & Videos .

关于android - 如何从 url 在 android 中播放 gif?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34562879/

相关文章:

android - 在 4*3 的网格中排列 12 个 RadioButton

android - 直接在 flutter 项目中使用插件,无需分离到另一个包或在 pubspec.yaml 中添加插件字段

android - 如何使用 "lookupKey"获取联系人图片?

python - 如何用 Linux 显示动画 gif?

iOS - 动画背景图片 (GIF)

android - 具有发光效果的动态生成线条

java - Android - 当应用程序被终止并重新启动时首选项不保存?

java - Android 如何更改电影大小 GIF

python - 如何制作 C++ 数组的动画色彩图?导出到Python并使用\matplotlib?

cocoa - NSImage 的动画在使用 NSKeyedArchiver 存档后丢失