1

I need to draw a line using android drawable, but this line need to has more than one color, and it cant be gradient. My target is as below:

Note the line with green, blue and orange colors.

I´ve read here a post that mentions that it could be done with an image in png, but i doesnt liked the idea.

Is there another clean solution?

Thanks.

andresmafra
  • 491
  • 7
  • 19

1 Answers1

2

You can use a layer list as like this:

<?xml version="1.0" encoding="UTF-8"?>
        <layer-list xmlns:android="http://schemas.android.com/apk/res/android">  
            <item android:drawable="@drawable/back" />
        <item>
                <shape android:shape="rectangle">
                   <solid android:color="#f000"/>
                </shape>
            </item> 
             <item  android:left="20dp">
                <shape android:shape="rectangle">
                    <solid android:color="#f001"/>
                </shape>
            </item> 
               <item android:left="60dp">
                <shape android:shape="rectangle">
                    <solid android:color="#f003"/>
                </shape>
            </item> 
          </layer-list> 

Set this as the background of your view

vipul mittal
  • 17,343
  • 3
  • 41
  • 44