Android Gradient With 4 Params
How can I make a gradient like this in xml I can not do it with just these params startColor='' centerColor='' endColor='' any ideas ?
Solution 1:
<?xml version="1.0" encoding="UTF-8"?><shapexmlns:android="http://schemas.android.com/apk/res/android"android:shape="rectangle" ><gradientandroid:angle="90"android:centerColor="#555994"android:endColor="#b5b6d2"android:startColor="#555994"android:type="linear" /><cornersandroid:radius="0dp"/></shape>
Solution 2:
if you want to draw it through shape you have to do work with layer-list
. You can think about it like two rectangles and every rectangle has its own gradient color.
Solution 3:
6 years too late, but the easiest way to do more complex gradients like this is via multiple overlapping shapes in a layer-list
, as Blackbelt mentioned.
The basic layout is:
- Rectangle 1 is centred at 20% down vertically. It starts at your grey colour, and centres & ends as pure white. By having the centre only partially down the drawable, the first grey -> white transition is achieved.
- Rectangle 2 is centred at 80% down vertically. It starts & ends as transparent, but has grey in the centre. As it is mostly transparent, it does not interfered with Rectangle 1.
This could also be achieved by having multiple drawables overlapping each other, but this way is simple enough. Here's a screenshot of it:
And here's the actual XML:
<?xml version="1.0" encoding="utf-8"?><layer-listxmlns:android="http://schemas.android.com/apk/res/android"><item><shape><gradientandroid:centerColor="#FFFFFF"android:centerY="20%"android:endColor="#FFFFFF"android:startColor="#AAAAAA" /></shape></item><item><shape><gradientandroid:centerColor="#AAAAAA"android:centerY="80%"android:endColor="@android:color/transparent"android:startColor="@android:color/transparent" /></shape></item></layer-list>
Post a Comment for "Android Gradient With 4 Params"