Android radial gradient
Asked Answered
C

2

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?

Calle answered 27/5, 2012 at 14:57 Comment(2)
i refer it to layout and also to textview it fill the whole screen, may i miss understand what you needChump
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.Turcotte
C
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 .

Chump answered 27/5, 2012 at 16:51 Comment(1)
not working for me. it always takes 1px base width. so 500%[p] gives me 5px radiusCiaracibber
T
12

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

Tucker answered 19/8, 2014 at 22:6 Comment(0)
C
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 .

Chump answered 27/5, 2012 at 16:51 Comment(1)
not working for me. it always takes 1px base width. so 500%[p] gives me 5px radiusCiaracibber

© 2022 - 2024 — McMap. All rights reserved.