Android radial gradient

Sebastian Nowak picture Sebastian Nowak · May 27, 2012 · Viewed 18.1k times · Source

I've got following drawable set as LinearLayout background:

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
   <item>
      <bitmap
         android:tileMode="repeat"
         android:dither="true"
         android:src="@drawable/bg"/>
   </item>


   <item>
      <shape android:shape="rectangle">
         <gradient
            android:startColor="#ffff0000"
            android:endColor="#ff00ff00"
            android:centerX="50%"
            android:centerY="50%"
            android:gradientRadius="50%"
            android:type="radial"/>
      </shape>
   </item>
</layer-list>

According to the docs, gradientRadius can be set to percentage of window/parent size. Unfortunetely... it's not working. The radius is 0. What am I doing wrong? Or what's wrong with Android?

I need the radial gradient to fill the whole screen. What's the workaround?

Answer

Daniel picture Daniel · Aug 20, 2014

A little bit late, but according to docs, you must set "50%p", not "50%". (Note the 'p' which indicates 'parent')