【问题标题】:asset path doesn't work with "/android_asset/" path资产路径不适用于“/android_asset/”路径
【发布时间】:2019-10-13 17:09:51
【问题描述】:

我正在尝试使用this library,像这样:

        val imageUrl = "file:///android_asset/error_apng.png"
        val animator = ApngAnimator(this@MainActivity).loadInto(iv_circle)
        animator.load(imageUrl)
        animator.play()

但它什么也没显示。但是,带有https://的示例网址可以正常工作。

我尝试了以下方法:

file://android_asset/error_apng

file:///android_asset/apng/error_apng

asset://error_apng.pn

assets://error_apng.png

assets://error_apng.png

README.md 表示我可以使用urlfile path。它有什么问题?

【问题讨论】:

  • 文件在哪里,在您的项目目录中还是在手机 SD 卡中?
  • 它在assets 文件夹中。

标签: android android-file android-assets


【解决方案1】:

你可以试试这个

val file = File("file:///android_asset/error_apng.png")
val animator = ApngAnimator(this@MainActivity).loadInto(iv_circle)
animator.load(file)
animator.play()

如果不起作用,请尝试将您的图片托管在图片托管网站中并使用网址。

【讨论】:

  • 它在示例源的评论中说。 // image url could be an url, or a file path. You could also load byteArray and file
  • @c-an 对不起。错过了那条评论。您是否尝试将其初始化为 File("file path")?。方法实现似乎确实支持 url、uri 和 file,所以它应该可以工作。
【解决方案2】:

图书馆似乎并不完美。尝试改用这个库: https://github.com/penfeizhou/APNG4Android

【讨论】:

  • APNG4Android with glide 仍然无法为我的资产文件设置动画。为什么?
  • @Victor Choy,请用您的代码和情况发布新问题。
  • 我通过读取和调试源解决了我的问题。主要研究是通过滑翔从图像中产生的缓存。缓存导致资产文件显示不正确。很烦人。 @c-an
猜你喜欢
  • 2012-08-29
  • 2011-07-12
  • 2022-06-10
  • 1970-01-01
  • 1970-01-01
  • 2015-12-12
  • 1970-01-01
  • 2020-05-16
  • 2015-01-12
相关资源
最近更新 更多