Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: show gradient like shadow using shape.xml

Hi I am trying to get shadow like gradient only on the top using the shape.xml

enter image description here

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>
like image 759
hari86 Avatar asked Sep 20 '16 06:09

hari86


2 Answers

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 ->

Image For Shadow

like image 86
Zahidul Islam Avatar answered Nov 10 '22 04:11

Zahidul Islam


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>
like image 21
Piyush Avatar answered Nov 10 '22 04:11

Piyush