使用 Glide 从 filesDir() 加载九个补丁
Load nine patch with Glide from filesDir()
我正在尝试从 filesDir() 加载一个 .9.png ,我之前已经从服务器下载到视图:
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 中构建,然后上传到服务器。 Source here
我正在尝试从 filesDir() 加载一个 .9.png ,我之前已经从服务器下载到视图:
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 中构建,然后上传到服务器。 Source here