2

I'm trying to achieve shadow around an oval using this code:

shadow = new Paint();
    shadow.setColor(Color.YELLOW);
    shadow.setShadowLayer(10, 0, 0, Color.YELLOW);

and the draw function goes like this:

c.drawOval(ovalRect, shadow);
super.draw(c); //Draws bitmap

So first of all it draw oval with the paint containing the shadow, and then on top of it draws bitmap with transparancy (Bitmap doesn't have any paint).

I get the following outcome: screenshot As you can see the shadow isn't spread along the oval, but it's getting cut out, what could cause this behavior?

Kara
  • 6,115
  • 16
  • 50
  • 57
AngryChicken
  • 360
  • 2
  • 16
  • maybe it's a padding issue ? – An-droid Aug 30 '13 at 12:27
  • That looks like to if you the thing where the 3 chip is on it(label, panel, idk) is to small. The shadow dosent fit on that so you have to make the panel, label or what you use bigger so the shadow fits in – Gerret Aug 30 '13 at 12:48
  • I would understand it, if the shadow was cut out only by the neighboring buttons, however, here we can see that it is cut out from the top as well. – AngryChicken Aug 30 '13 at 12:59
  • I have a similar result when using textview with shadows. I fix it by adding a padding – gian1200 Jan 29 '14 at 02:36

2 Answers2

0

You can try this maybe by changing the radius :

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >

    <!-- Drop Shadow Stack -->
    <item>
        <shape>
            <corners android:radius="12dp" />

            <padding
                android:bottom="1dp"
                android:left="1dp"
                android:right="1dp"
                android:top="1dp" />

            <solid android:color="#00CCCCCC" />
        </shape>
    </item>
    <item>
        <shape>
            <corners android:radius="12dp" />

            <padding
                android:bottom="1dp"
                android:left="1dp"
                android:right="1dp"
                android:top="1dp" />

            <solid android:color="#10CCCCCC" />
        </shape>
    </item>
    <item>
        <shape>
            <corners android:radius="12dp" />

            <padding
                android:bottom="1dp"
                android:left="1dp"
                android:right="1dp"
                android:top="1dp" />

            <solid android:color="#20CCCCCC" />
        </shape>
    </item>
    <item>
        <shape>
            <corners android:radius="12dp" />

            <padding
                android:bottom="1dp"
                android:left="1dp"
                android:right="1dp"
                android:top="1dp" />

            <solid android:color="#30CCCCCC" />
        </shape>
    </item>
    <item>
        <shape>
            <corners android:radius="12dp" />

            <padding
                android:bottom="1dp"
                android:left="1dp"
                android:right="1dp"
                android:top="1dp" />

            <solid android:color="#50CCCCCC" />
        </shape>
    </item>

    <!-- Background -->
    <item>
        <shape>
            <solid android:color="@android:color/white" />

            <corners android:radius="12dp" />
        </shape>
    </item>

</layer-list>
An-droid
  • 6,433
  • 9
  • 48
  • 93
0

Late to the game, but still might help someone:

Try to set android:clipChildren="false" to the parent ViewGroup.

Depending on your layout you also might need to additionally add a bit of padding to the parent and set android:clipToPadding="false" on that parent.

That usually allows the children (and thus also their shadows) to draw outside of their boundaries.

ubuntudroid
  • 3,680
  • 6
  • 36
  • 60