XML radial gradient with parent size

I am trying to create a component for creating custom shadows for buttons or other components, I know that with a 9-patch file or pager it will be easier, but I want to change its color and size programmatically and in its states (pressed, etc.), so I decided to try with 9 images, all in XML format, so that the shadows displayed their gradient from the component side.

<!-- Left Shadow layer --> <item> <shape android:shape="rectangle" > <gradient android:angle="0" android:endColor="#FFFF0000" android:startColor="#00FF0000" /> </shape> </item> 

It seems that the problem lies in the corners, and the android: gradientRadius parameter is now set to a fixed size, but in the context help they say that you can set 10% p as a percentage of the base size or 10% p of the parent, that I want it to set the radius to 100 % p, so the gradient will always go from the main color and disappear at the edge of the square.

- EDIT -

Android doc about gradientRadius gradientRadius

 <shape android:shape="rectangle" > <gradient android:endColor="#00FF0000" android:startColor="#FFFF0000" android:gradientRadius="18" android:centerX="100%" android:centerY="100%" android:type="radial" /> </shape> 

And here is where im is now :( I don't know how I can set this size according to its parent representation.

Any help would be appreciated when I finished with the component, I will put the code back :), so typical buttons can have custom shadows in xml.

Image of a well-deserved component.

- Edit -

I'm still wondering this :) no one has a clue?

Button with radia gradients

+8
android android-layout android-xml
source share
1 answer

I think you should abandon xml and implement drawable in code. When you extend the Drawable class, you can get the size as a rectangle using the getBounds () method. You can also dynamically recount the onBoundsChange method. You can also easily build gradients and use them in a Paint object (setShader method)

+2
source share

All Articles