问题
How can I load vector drawables from an online location e.g http://arsenal.com/image.xml and display it as an image
回答1:
Do you need to support VectorDrawables on older devices? If so, then I don't think it is currently possible. AFAIK the support library will only let you assign a VectorDrawable if it is a resource (ie. via setImageResource()
).
http://android-developers.blogspot.co.nz/2016/02/android-support-library-232.html
The alternative would be to use SVGs instead and use one of the SVG libraries for Android.
However, if you only need to support Lollipop and later, then it should be possible using the process as set out below. Though I haven't tried it myself.
First, fetch the VectorDrawable file as a Stream. As an example, see this question.
You will then need to make an XmlPullParser instance.
xppXmlPullParserFactory factory = XmlPullParserFactory.newInstance();
XmlPullParser xpp = factory.newPullParser();
Then tell the parser about the stream
xpp.setInput(input, null);
Then you can get a VectorDrawable by calling inflate(). Pass it the parser instance.
VectorDrawable vd = new VectorDrawable();
vd.inflate(getResources(), xpp, null, null);
Then you should be able to assign the drawable to your ImageView.
imageView.setImageDrawable(vd);
Good luck!
来源:https://stackoverflow.com/questions/39663106/load-vector-drawables-from-an-online-location-android