-
Notifications
You must be signed in to change notification settings - Fork 253
Home
"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
- Can't draw circle shadow.
- Not possible to set shadow position.
- Not possible to set shadow color. (Make shadow darker or lighter)
- No method to set selector for shadow (Lift on touch)
Background Image approach
- For every component you need shadow image for all
drawable-dpi
folders - 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.
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.