7

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?

Sebastian Nowak
  • 5,607
  • 8
  • 67
  • 107
  • i refer it to layout and also to textview it fill the whole screen, may i miss understand what you need – Android Stack May 27 '12 at 15:40
  • I was never able to get a non-integer value as the gardientRadius. All the examples I found are in pixels, not even in dip. As a workaround, you could create the drawable in code, and set the radius after measuring the view. – yoah May 27 '12 at 17:00

2 Answers2

12

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

Daniel
  • 1,287
  • 12
  • 12
5

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 .

Android Stack
  • 4,314
  • 6
  • 31
  • 49