What more memory is more intense? Drawing using popped xml or drawing image?

I have an application that has several buttons, for this I use different available images (png) to set the background.

I know that you can draw custom buttons in android using the "drawable xml" files. In them you can define shapes and set gradients, indents, etc. For this particular form. This reduces the size of the application (since using it eliminates all PNGs).

background.xml

<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle"> <gradient android:startColor="#FFFF0000" android:endColor="#FFFFFFFF" android:angle="90" /> <padding android:left="4dp" android:top="4dp" android:right="4dp" android:bottom="4dp" /> <corners android:radius="4dp" /> 

My question is, which is more preferable, from a memory point? What are the main advantages / disadvantages of one of them?

+4
source share
1 answer

Creating drawable in xml will

1) Less expensive since the entire image does not need to be loaded into memory.

2) He will not suffer from problems with scaling.

For simple backgrounds and gradients, I would definitely use XML layouts. If this is too complicated for the XML layout, go to the actual PNG images.

+4
source

All Articles