Android radial gradient

18.5k views Asked by At

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?

2

There are 2 answers

1
Android Stack On BEST ANSWER

if i understand well what you need you have to make layout which referded by drawable

( "match_parent" ) ,

as below :

 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:orientation="vertical" 
     android:background="@drawable/"your drawable xml name">

hope this help .

0
Daniel On

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