Sunday, July 15, 2012

Gradient in XML– easy as pi

 
Tired of using solid background colors but you think it’s a bit trouble to use you favorite graphics tool too create interesting backgrounds for you controls or layouts? well, creating gradients in your android app is easy enough, here’s an example:


  1. In your drawable folder , create an xml file.
  2. the next code creates a gradient which is from top to bottom, with start color of white and end color of somewhat orange, it begins to get a strong fade after 90% of the measure of the container view.

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape>
<gradient
android:angle="90"
android:startColor="#fff"
android:endColor="#FFA812"
android:type="linear"
android:centerY="0.9"
/>
</shape>
</item>
</selector>