【问题标题】:Load vector drawables from an online location android从在线位置android加载矢量drawables
【发布时间】:2016-09-23 14:19:50
【问题描述】:

如何从在线位置(例如 http://arsenal.com/image.xml)加载矢量绘图并将其显示为图像

【问题讨论】:

  • 将 URL 传递给浏览器?或者你是什么意思?
  • 获取url并使用imageloader显示

标签: android svg android-vectordrawable


【解决方案1】:

您需要在旧设备上支持 VectorDrawables 吗?如果是这样,那么我认为目前是不可能的。 AFAIK 支持库仅允许您分配 VectorDrawable 如果它是资源(即通过setImageResource())。

http://android-developers.blogspot.co.nz/2016/02/android-support-library-232.html

替代方法是使用 SVG 并使用 Android 的 SVG 库之一。

但是,如果您只需要支持 Lollipop 及更高版本,则应该可以使用如下所述的过程。虽然我自己没试过。

首先,将 VectorDrawable 文件作为 Stream 获取。例如,请参阅this question

然后您需要创建一个XmlPullParser 实例。

xppXmlPullParserFactory factory = XmlPullParserFactory.newInstance();
XmlPullParser xpp = factory.newPullParser();

然后告诉解析器有关流的信息

xpp.setInput(input, null);

然后您可以通过调用inflate() 来获取 VectorDrawable。将解析器实例传递给它。

VectorDrawable  vd = new VectorDrawable();
vd.inflate(getResources(), xpp, null, null);

那么你应该能够将drawable分配给你的ImageView。

imageView.setImageDrawable(vd);

祝你好运!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-05-08
    • 1970-01-01
    • 1970-01-01
    • 2013-05-13
    • 2018-05-26
    • 1970-01-01
    相关资源
    最近更新 更多