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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With