0 works

Android LinearLayout gradient background


dashboard

Posted 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 to Clipboard

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

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

,

>> Browse more code snippets

more_vert