我想在 imgur 应用程序等 android 应用程序中从 url 播放动画 gif。 Imagur 非常棒而且非常快。我正在使用 webview 加载 gif,但它不符合要求。
最佳答案
您可以使用 Glide在 ImageView
上播放 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/