Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Which is more memory intensive? Drawing using a drawable xml or drawable image?

I have an application which has several buttons, for these I use different drawable images (png) to set the backgrounds.

I am aware that you can draw custom buttons in android using the "drawable xml" files. In those you can define shapes and set gradients, padding, etc for that particular shape. This reduces the size of the application (since using it would eliminate all the 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? Also what are the major advantages / disadvantages of one to the other?

like image 373
pixelscreen Avatar asked Jul 27 '12 11:07

pixelscreen


1 Answers

Creating the drawable in xml would be

1) Less expensive as the whole image will not need to be loaded in to memory.

2) It won't suffer from scaling issues.

For simple backgrounds and gradients, I would definitely use XML layouts. If it is something too complicated for an XML layout, then go for actual PNG images.

like image 72
Aswin Kumar Avatar answered Oct 05 '22 22:10

Aswin Kumar