2

I am trying to draw a shape that has three rectangular shapes:

  1. solid color
  2. gradient
  3. white line

How do I do that?

When I try this, it does not work. The layout has the parent color.

<shape 
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle"
    android:height="60px"
    >
    <shape 
        android:shape="rectangle" 
        android:height="30px"
        >
        <solid 
            android:color="#ff297baf" 
            />
    </shape>
    <shape 
        android:shape="rectangle"
        android:height="30px"
        >
         <gradient
  android:type="linear"
  android:startColor="#ff297baf"
  android:endColor="#ff16c0e3"
  android:angle="270"/> 
    </shape>
    <shape
        android:shape="rectangle"
        android:height="3px"
        >
        <solid 
            android:color="#FFFFFFFF"
            />
    </shape>
</shape>

I am trying to make a gradient in 3 colors. Start with a solid color #ff297baf, at 60% start a gradient from #ff297baf to #ff16c0e3 and add a while line at the end.

Lii
  • 11,553
  • 8
  • 64
  • 88
dropsOfJupiter
  • 6,763
  • 12
  • 47
  • 59
  • You need to give a lot more information here. Do you have example code of what you're trying so far? Why do you need a solid color AND a gradient? Is it a transparent gradient overlay? The white line, is it an outline? Should it go inside the shape? – Kevin Coppock Dec 10 '10 at 22:07
  • Please add your comment to the question and format it a bit. – Mark Storer Dec 10 '10 at 23:42
  • its not transparent overlay. White line is an outline. Normally I would do this in HTML: "border-bottom: solid 2px white". It does not have to do inside but I can't get any other shapes on the view. The compiler complains that is supposed to be root. – dropsOfJupiter Dec 11 '10 at 00:03

1 Answers1

11

If you're going to look into using multiple shapes, you should try a LayerListDrawable. Something like this works for me, but only for your example height of 60px. You may have to modify it to suit your needs exactly, but this should get you a good start:

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
    <shape android:shape="rectangle">
        <gradient
            android:angle="270"
            android:endColor="#ff16c0e3"
            android:startColor="#ff297baf"
            android:type="linear" />
    </shape>
</item>
<item android:top="57px">
    <shape android:shape="rectangle">
        <solid android:color="#FFFFFFFF" />
        <size android:height="3px" />
    </shape>
</item>

Slavi Petrov
  • 320
  • 6
  • 12
Kevin Coppock
  • 133,643
  • 45
  • 263
  • 274