Android LinearLayout gradient background

EMBED

Saved by @Awais malik #android #java #xml

Step 0: First of all go to app->res->drawable and create new Drawable resource file and replace code with following code, you can change color and angle for different results .

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

Step 1: Now go to res->layout and in .xml files where you want to set gradient as background in layout or image view

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:background="@drawable/gradient">
    
</LinearLayout>

// for Image View
<ImageView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/gradient"
    />

content_copyCOPY

In this tutorial i will teach you how to create and set gradient background to a layout or image view

,