How to display gradient effect from top to bottom in android

<shape xmlns:android="http://schemas.android.com/apk/res/android" >

    <gradient

        android:angle="90"
        android:type="linear"
        android:startColor="#FFFFFF"
        android:endColor="#000000" />

</shape>

here if you set the angle to the 270 the start color will appear at the bottom and the end color at the top if you set the angle to 90 it will be reversed


make an xml file in your dawable folder name it like gradient_bg.xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <gradient 
        android:startColor="#000" 
        android:endColor="#fff"
        android:angle="90"
     />
</shape>

and set it as background to your View.

android:background="@drawable/gradient_bg"

or

setBackgroundResource(R.drawable.gradient_bg);

Tags:

Android