Skip to content
Dmytro Danylyk edited this page Mar 10, 2015 · 5 revisions

Why this library was created?

"Within the material environment, virtual lights illuminate the scene and allow objects to cast shadows. A key light creates directional shadows, while an ambient light creates consistent, soft shadows from all angles." - Google Material Design Specs

With introduction of Material Design shadow is now highly usable 'ingredient' for 'cooking' Android Material Components like Raised Button, Floating Action Button or just background for dialog.

To display shadow for your components you have 2 approach:

  • Use Card View
  • Set background image

Card View approach

  1. Can't draw circle shadow.
  2. Not possible to set shadow position.
  3. Not possible to set shadow color. (Make shadow darker or lighter)
  4. No method to set selector for shadow (Lift on touch)

Background Image approach

  1. For every component you need shadow image for all drawable-dpi folders
  2. Ton's of resources increase apk size

Because CardView is not enough and making a lot of background images is annoying, I have created ShadowLayout.

How it works?

ShadowLayout - is a custom view group which wrap View and display shadow for pre Lollipop devices. It doesn't analyze view outline, so ShadowLayout can draw square, rounded corner or circle shadow.

To draw shadow, Paint object with shadow layer is used. Generated Bitmap is set as a background to ShadowLayout with padding, to prevent child view overlap shadow.

Clone this wiki locally