Nine-Patch Drawable vs Shape Drawable. Which should be preferred?
android
Solution
Shape drawable is great for gradient kind of images with simple constant color changes. On the other hand, 9-patch images are great for images with lots of detail, constant color in streching regions.
Problem
My co-worker and I developed two apps in parallel, each with similar styling. The main view background of these apps is a radial gradient. He implemented his as a nine-patch image and I did it with a shape drawable. Both generate similar and acceptable results. So my question is, which should we use? Are there are trade-offs between memory consumption and performance? I imagine that the image could take time to load, but that the shape drawable takes more time to draw (due to calculations). Are these then stored in a cache and those penalties only happen the first time they are displayed or are these issues on-going??? Shape Drawable: ``` <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle"> <gradient android:startColor="#003472" android:endColor="#000034" android:gradientRadius="350" android:type="radial"/> </shape> ``` Nine Patch: