Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Nine-Patch Drawable vs Shape Drawable. Which should be preferred?

Tags:

android

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:

enter image description here

like image 229
jsmith Avatar asked Jun 12 '12 13:06

jsmith


People also ask

Which of the following is the correct extension or 9 patch file?

9. png file extension. Double-click your new NinePatch file to open it in Android Studio.

What is 9 patch image in Android?

A 9 patch image is a regular png (. PNG) image which is needful for android app developers where they require to wrap any content within a background image without pixelating the background image.

What is NinePatchDrawable?

android.graphics.drawable.NinePatchDrawable. A resizeable bitmap, with stretchable areas that you define. This type of image is defined in a . png file with a special format.


1 Answers

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.

like image 68
Gökhan Barış Aker Avatar answered Oct 21 '22 04:10

Gökhan Barış Aker