Material Shadow is a library for seamlessly integrating Material shadows.
The library takes existing material shadows to next level by adding the following features :Ā
Support for shadow offsets,Ā
Support for shadow intensity,Ā
Shadows for semi-transparent views,Ā
Support for Async Shadow calculationsĀ
How does Material Shadow work ?
The MaterialShadowViewWrapper is an extension of Relative Layout. The MaterialShadowFrameLayoutWrapper is an extension of FrameLayout. Use any one of them as per your convenience.
Did you use ever : Building UI with ConstraintLayout in Android?
All the child views go through the same process of generating shadow as given below :
First a bitmap is generated from the drawing cache of the view.
The bitmap is traversed pixel by pixel to remove all transparent pixels and get a list of points corresponding to the actual outline of the content of the view.
Since the points corresponding to outline may give a concave path, hence GrahamScan algorithm is used to generate a convex hull of the outline points.
A path is created from the points of the resulting convex hull.
This path is passed to a CustomViewOutlineProvider object that is later attached to the view itself.
Hence we get a convex shadow for any type of view based on its content.
P.S. : All the calculations related to graham scan are done asynchronously by default. This behavior can be controlled by calculateAsync parameter.