harjot-oberai / MaterialShadows
- среда, 31 мая 2017 г. в 03:12:33
Java
A library for supporting convex material shadows
A library for seamlessly integrating Material shadows. The library takes existing material shadows to next level by adding the following features :
shadowAlpha
attribute.Just add the following dependency in your app's build.gradle
dependencies {
compile 'com.sdsmdg.harjot:materialshadows:1.1.0'
}
The MaterialShadowViewWrapper
is an extension of Relative Layout
. All the child views go through the same process of generating shadow as given below :
CustomViewOutlineProvider
object that is later attached to the view itself.P.S. : All the calculations related to graham scan are done asynchronously by default. This behavior can be controlled by calculateAsync
parameter. (Thanks Yaroslav!)
<com.sdsmdg.harjot.materialshadows.MaterialShadowViewWrapper
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_width="130dp"
android:layout_height="130dp"
android:elevation="5dp"
android:src="@drawable/poly" />
</com.sdsmdg.harjot.materialshadows.MaterialShadowViewWrapper>
<com.sdsmdg.harjot.materialshadows.MaterialShadowViewWrapper
android:layout_width="match_parent"
android:layout_height="match_parent"
app:shadowOffsetX="-15"
app:shadowOffsetY="30">
<ImageView
android:layout_width="130dp"
android:layout_height="130dp"
android:elevation="10dp"
android:src="@drawable/poly" />
</com.sdsmdg.harjot.materialshadows.MaterialShadowViewWrapper>
<com.sdsmdg.harjot.materialshadows.MaterialShadowViewWrapper
android:layout_width="match_parent"
android:layout_height="match_parent"
app:shadowOffsetX="-15"
app:shadowOffsetY="30"
app:shadowAlpha="0.9">
<ImageView
android:layout_width="130dp"
android:layout_height="130dp"
android:elevation="10dp"
android:src="@drawable/poly" />
</com.sdsmdg.harjot.materialshadows.MaterialShadowViewWrapper>
<com.sdsmdg.harjot.materialshadows.MaterialShadowViewWrapper
android:layout_width="match_parent"
android:layout_height="match_parent"
app:shadowOffsetX="-30"
app:shadowOffsetY="30">
<ImageView
android:layout_width="130dp"
android:layout_height="130dp"
android:elevation="10dp"
android:background="#55000000" />
</com.sdsmdg.harjot.materialshadows.MaterialShadowViewWrapper>
XML attribute | Java set methods | Description | Default Value |
---|---|---|---|
shadowOffsetX | setOffsetX(...) | Set the X-offset of the shadow | 0.0f |
shadowOffsetY | setOffsetX(...) | Set the Y-offset of the shadow | 0.0f |
shadowAlpha | setShadowAlpha(...) | Set the value of shadow intensity (alpha) | 1.0f |
calculateAsync | setShouldCalculateAsync(...) | Set the flag for async shadow calculations. | true |
showWhenAllReady | setShowShadowsWhenAllReady(...) | Set the flag for showing all shadows after all calculations are over | true |
animateShadow | setShouldAnimateShadow(...) | Set the flag for shadow animation | true |
animationDuration | setAnimationDuration(...) | Set the value of shadow animation duration. | 300ms |
MaterialShadowViewWrapper
. Hence if the desired views are placed inside a Linear Layout or some other view group, then each view must be wrapped by a seperate MaterialShadowViewWrapper
. This doesn't affect the performance as the number of operations are still the same, but affects the quality of code.MaterialShadowViewWrapper
is assigned same offset and shadow intensity. If fine control over every view's shadow is required then it must be wrapped inside its own MaterialShadowViewWrapper
. Again this doesn't affect the performance, just the quality of code.MaterialShadows is licensed under MIT license
. View license.