Android: show gradient like shadow using shape.xml
21,709
Solution 1
No need to use Layer-list , You can do it by Gradient
. Try this flowing code ->
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<gradient android:startColor="#b4909090" android:endColor="#b4fafafa" android:angle="90"/>
</shape>
Change the startColor
and endColor
as you want. And the result is ->
Solution 2
Simply use:
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" >
<gradient
android:type="linear"
android:centerX="78%"
android:startColor="#FFf7f7f7"
android:centerColor="#FFC0C0C0"
android:endColor="#FFbebebe"
android:angle="90"/>
</shape>
Author by
hari86
Updated on September 20, 2020Comments
-
hari86 over 3 years
Hi I am trying to get shadow like gradient only on the top using the shape.xml
From the image am wrapping the buttons in a linear layout and I want to give the gradient on top of the layout.
Am doing as below but it is not working out
<?xml version="1.0" encoding="utf-8"?> <layer-list xmlns:android="http://schemas.android.com/apk/res/android" > <item> <shape android:shape="rectangle"> <stroke android:width="1dp" android:color="#f0f0f0" /> <solid android:color="#f0f0f0" /> </shape> </item> <item android:top="1dp"> <shape android:shape="line"> <gradient android:angle="90" android:type="linear" android:startColor="#FFFFFF" android:endColor="#000000" /> </shape> </item> </layer-list>
-
hari86 over 7 yearsthat code is giving gradient to whole linear layout..just want a line to the layout
-
Gokhan Arik over 5 yearsYou didn't specify how to use this. This is valid if you have an
ImageView
above your view and set this as background to theImageView
. When you apply this as background to theLinearLayout
entire view will have gradient background. He wants his background to be white with a gradient border on top.