Question

I want to have, say, an outline of a dog in my app that maintains an aspect ratio but grows depending on the available screen space. I also want to be able to color its fill on the fly depending on user input. What is the best way to do this?

It's really an SVG that I want but Android doesn't support that. Am I stuck making a custom view or doing it manually in a canvas? Is there another way?

I come from WPF and in that world you can specify a path in XAML that you exported from Blend that automatically scales to fit. Is there something similar to that where I can generate the outline somewhere else and import it into an Android drawable or custom view? Basically, I'd like to avoid having to draw this complicated shape arc by arc.

Was it helpful?

Solution

The WebView widget supports SVG - at least from Android 3.0 onwards. Alternatively, you could use one of the SVG rendering libraries as a more lightweight solution. The various derivatives and forks of svg-android support swapping colours at runtime.

Update: My SVG library AndroidSVG also now supports colour changing from version 1.3. It uses CSS.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top