Performance: 9-patch vs Custom drawable
What are (if any) are the performance gains for using a 9-patch image with rounded corners for say the background of a dynamically changing String of text, vs a custom Shape drawable that's programmatically generated by Android using Canvas or XML?
A coworker of mine insists on using custom Shape drawables for everything, and all my research points to this being a bad idea for performance reasons.
If you can provide some benchmarks that would be amazing. My coworker is more easily convinced by benchmarks...
Posted Aug 22, 2014, 2:26 PM UTC · edited
Custom drawable as in a .png image in your resources or a .xml? I believe xml files are better for performance and easier to maintain if you know how to make backgrounds from them and you're not good at Photoshop.
I meant either an xml shape or using Android Canvas APIs. I should have been clearer. Sorry!
I think you're talking about a custom View, not a custom drawable.
Usually you would want to make a custom View for added functionality (e.g. making a button that automatically bounces every time it's clicked), but if you're just wanting, say, a button that looks a certain way, 8 times out of 10 a 9-patch or xml is not only easier to program for but probably better for performance.
To a certain extent, yeah, a custom View.
I would think an xml shape would be more expensive to draw than 9-patch though. Yes?