我在imageView中添加了一个动画gif图像.我无法将其视为gif图像.没有动画.它看起来像一个静止图像.我想知道如何将其显示为gif图像.
我是Android平台的新手.我想开发一个动态壁纸应用程序.当我在搜索引擎中对此进行搜索时,他们中的许多人创建了一个动态壁纸作为他们的代码(使用SurfaceView和Canvas),我对此并不十分了解.我怀疑的是,任何可能将.gif图像设置为动态壁纸.
在动态壁纸中,我有一个Canvas实例,我希望将GIF/WEBP内容绘制成,通过Glide加载.
我想与滑翔做到这一点,原因是它在我过去找到了同样的事情(的解决方案提供了一些优势在这里,仓库在这里):
Glide似乎已经过优化,只能用于普通的UI(视图).它有一些基本的功能,但对我正在尝试做的最重要的功能似乎是私密的.
我使用官方Glide库(v 3.8.0)进行GIF加载,使用GlideWebpDecoder进行WEBP加载(使用相同版本).
加载其中每个的基本调用是这样的:
GIF:
GlideApp.with(this).asGif()
.load("https://res.cloudinary.com/demo/image/upload/bored_animation.gif")
.into(object : SimpleTarget<GifDrawable>() {
override fun onResourceReady(resource: GifDrawable, transition: Transition<in GifDrawable>?) {
//example of usage:
imageView.setImageDrawable(resource)
resource.start()
}
})
Run Code Online (Sandbox Code Playgroud)
WEBP:
GlideApp.with(this).asDrawable()
.load("https://res.cloudinary.com/demo/image/upload/fl_awebp/bored_animation.webp")
// .optionalTransform(WebpDrawable::class.java, WebpDrawableTransformation(CircleCrop()))
.into(object : SimpleTarget<Drawable>() {
override fun onResourceReady(resource: Drawable, transition: Transition<in Drawable>?) {
//example of usage:
imageView.setImageDrawable(resource)
if (resource is Animatable) {
(resource as Animatable).start()
}
}
})
Run Code Online (Sandbox Code Playgroud)
现在,请记住我并没有真正的ImageView,而是我只有一个Canvas,我可以通过surfaceHolder.lockCanvas()调用获得. …