Reputation: 411
How can I make a gradient like this in xml
I can not do it with just these params
startColor=""
centerColor=""
endColor=""
any ideas ?
Upvotes: 1
Views: 205
Reputation: 7989
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:
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-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape>
<gradient
android:centerColor="#FFFFFF"
android:centerY="20%"
android:endColor="#FFFFFF"
android:startColor="#AAAAAA" />
</shape>
</item>
<item>
<shape>
<gradient
android:centerColor="#AAAAAA"
android:centerY="80%"
android:endColor="@android:color/transparent"
android:startColor="@android:color/transparent" />
</shape>
</item>
</layer-list>
Upvotes: 0
Reputation: 157467
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.
Upvotes: 0
Reputation: 6533
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" >
<gradient
android:angle="90"
android:centerColor="#555994"
android:endColor="#b5b6d2"
android:startColor="#555994"
android:type="linear" />
<corners
android:radius="0dp"/>
</shape>
Upvotes: 1