我正在尝试用Picasso加载下载到sd卡中的svg文件,但它不起作用.
File file = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM).getAbsolutePath()+"/secciones.svg");
Picasso.with(context).load(file).into(holder.ivIcon);
是否可以加载下载到imageView中的.svg?
解决方法:
您可以通过在将SVG设置为ImageView之前将SVG转换为drawable来实现此目的.为了这个目的,有一个很好的图书馆(有点旧和未管理)Here,但我尝试并为我工作.代码如下:
File dir = Environment.getExternalStorageDirectory();
File yourFile = new File(dir, "your_file_path/filename.svg");
try {
FileInputStream fileInputStream = new FileInputStream(yourFile);
SVG svg = SVGParser.getSVGFromInputStream(fileInputStream);
Drawable drawable = svg.createPictureDrawable();
imageView.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
imageView.setImageDrawable(drawable);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
标签:android,svg,picasso
来源: https://codeday.me/bug/20190706/1392428.html