android - 使用 Glide 从 filesDir() 加载九个补丁
问题描述
我正在尝试从我之前从服务器下载的filesDir()加载.9.png到View:
Glide.with(context).asDrawable().load(f.absolutePath).dontTransform().into(object : CustomTarget<Drawable>() {
override fun onLoadStarted(placeholder: Drawable?) {
super.onLoadStarted(placeholder)
Log.v("DRAWABLE_TEST", "onLoadStarted")
}
override fun onLoadFailed(errorDrawable: Drawable?) {
super.onLoadFailed(errorDrawable)
Log.e("DRAWABLE_TEST", "onLoadFailed")
}
override fun onResourceReady(resource: Drawable, transition: Transition<in Drawable>?) {
Log.v("DRAWABLE_TEST", "onResourceReady")
view.background = resource
}
override fun onLoadCleared(placeholder: Drawable?) {
}
})
但我只得到拉伸的正常可绘制对象。
知道我应该如何加载它吗?
解决方案
好的,我已经做到了,但 Glide 没有:
val bmp = BitmapFactory.decodeFile(f.absolutePath)
val chunk = bmp.ninePatchChunk
val ninePatchDrawable = NinePatchDrawable(context.resources, bmp, chunk, Rect(), null)
但是,在下载 *.9.png 图像之前,它们应该在一些 APK 中构建,然后上传到服务器。来源在这里
推荐阅读
- javascript - 单击另一个下拉框时如何关闭任何打开的下拉框?
- postgresql - 如何将 Oracle Next_Day 函数转换为 Postgres SQL?
- python - Python - 链表问题和相关性
- c# - ASP.NET Core EventLog 未注册
- bluetooth-lowenergy - 低功耗蓝牙模糊测试
- azure - Azure 函数 - 当前 Azure 资源名称
- javascript - 使用 JavaScript 将数组的值交织在适当的位置
- .net - 升级到 Visual Studio 15.9.6 后,目标框架下拉列表中缺少 .NET Core 选项
- bash - echo -n 使用管道函数失败
- windows - 在机器代码中挂钩消息 0x202 并检查相关的窗口过程?