Android - draw z-depth shadow of MaterialDesign

Overview

ZDepthShadowLayout

Android - draw z-depth shadow of MaterialDesign

Demo

ZDepthShadowLayout GIF

Screen Capture

ZDepthShadowLayout GIF

Download

apply plugin: 'com.android.application'

repositories {
    maven {
        url "https://jitpack.io"
    }
}

android {
    // something code...
}

dependencies {
    compile 'com.github.ShogoMizumoto:ZDepthShadowLayout:1.0.4'
}

How to Use

<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:shadow="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <app.mosn.zdepthshadowlayout.ZDepthShadowLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        shadow:z_depth="z_depth1"
        shadow:z_depth_shape="rect"
        shadow:z_depth_padding="z_depth5">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Change ZDepth"
            android:background="@android:color/white"/>

    </app.mosn.zdepthshadowlayout.ZDepthShadowLayout>

</RelativeLayout>

Attribute

configuration

<app.mosn.zdepthshadowlayout.ZDepthShadowLayout
    shadow:z_depth="z_depth1"         // enum
    shadow:z_depth_shape="rect"       // enum
    shadow:z_depth_padding="z_depth5" // enum
    shadow:z_depth_animDuration="150" // integer
    shadow:z_depth_doAnim="true"      // boolean
/>

attrs.xml

<resources>
    <declare-styleable name="ZDepthShadowLayout">
        <attr name="z_depth" format="enum">
            <enum name="z_depth0" value="0"/>
            <enum name="z_depth1" value="1"/>
            <enum name="z_depth2" value="2"/>
            <enum name="z_depth3" value="3"/>
            <enum name="z_depth4" value="4"/>
            <enum name="z_depth5" value="5"/>
        </attr>
        <attr name="z_depth_shape" format="enum">
            <enum name="rect" value="0"/>
            <enum name="oval" value="1"/>
        </attr>
        <attr name="z_depth_padding" format="enum">
            <enum name="z_depth0" value="0"/>
            <enum name="z_depth1" value="1"/>
            <enum name="z_depth2" value="2"/>
            <enum name="z_depth3" value="3"/>
            <enum name="z_depth4" value="4"/>
            <enum name="z_depth5" value="5"/>
        </attr>
        <attr name="z_depth_paddingLeft" format="enum">
            <enum name="z_depth0" value="0"/>
            <enum name="z_depth1" value="1"/>
            <enum name="z_depth2" value="2"/>
            <enum name="z_depth3" value="3"/>
            <enum name="z_depth4" value="4"/>
            <enum name="z_depth5" value="5"/>
        </attr>
        <attr name="z_depth_paddingTop" format="enum">
            <enum name="z_depth0" value="0"/>
            <enum name="z_depth1" value="1"/>
            <enum name="z_depth2" value="2"/>
            <enum name="z_depth3" value="3"/>
            <enum name="z_depth4" value="4"/>
            <enum name="z_depth5" value="5"/>
        </attr>
        <attr name="z_depth_paddingRight" format="enum">
            <enum name="z_depth0" value="0"/>
            <enum name="z_depth1" value="1"/>
            <enum name="z_depth2" value="2"/>
            <enum name="z_depth3" value="3"/>
            <enum name="z_depth4" value="4"/>
            <enum name="z_depth5" value="5"/>
        </attr>
        <attr name="z_depth_paddingBottom" format="enum">
            <enum name="z_depth0" value="0"/>
            <enum name="z_depth1" value="1"/>
            <enum name="z_depth2" value="2"/>
            <enum name="z_depth3" value="3"/>
            <enum name="z_depth4" value="4"/>
            <enum name="z_depth5" value="5"/>
        </attr>
        <attr name="z_depth_animDuration" format="integer"/>
        <attr name="z_depth_doAnim" format="boolean"/>
    </declare-styleable>
</resources>

What is ZDepth?

ZDepthShadowLayout GIF

Example : z-depth 5

ZDepthShadowLayout GIF

Outline

ZDepthShadowLayout GIF

Example

ZDepthShadowLayout GIF

MIT License

This library is released under the MIT License, see LICENSE.txt.

Comments
  • Great!!, but...the background of the shadow is not translucent. T^T

    Great!!, but...the background of the shadow is not translucent. T^T

    I set a ZDepthShadowLayout to a Toolbar, but as you see below: Shadow line can be seen clearly, it can't be vaguely revealed under the words, this is not a perfect effect, can't accept T^T

    device-2015-04-02-195315

    opened by drakeet 4
  • set shape to oval ,but get rect.Maybe it's casued by the customview in it.

    set shape to oval ,but get rect.Maybe it's casued by the customview in it.

    109

                <RelativeLayout
                    android:layout_weight="1"
                    android:layout_width="match_parent"
                    android:layout_height="0dp">
                    <app.mosn.zdepthshadowlayout.ZDepthShadowLayout
                        android:id="@+id/zlayout_main"
                        android:layout_gravity="center"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        app:z_depth="z_depth1"
                        app:z_depth_shape="oval"
                        app:z_depth_padding="z_depth5">
    
                        <com.tinylight.waterwave.WaterWaveProgress
                            android:layout_gravity="center"
                            android:id="@+id/waterwave_main"
                            android:layout_width="@dimen/ph_size_current"
                            android:layout_height="@dimen/ph_size_current"
                            android:layout_weight="1"
                            style="@style/WaterWave_normal"/>
    
                    </app.mosn.zdepthshadowlayout.ZDepthShadowLayout>
    
                </RelativeLayout>
    
    opened by tinybright 0
  • It can cause memory leaks When used in RecyclerView ListView aso

    It can cause memory leaks When used in RecyclerView ListView aso

    It can cause memory leaks When used in RecyclerView ListView and so on Because the method onAttachedToWindow() well be called multiple times in ZDepthShadowLayout.java and it always called addView(mShadowView,0) but it's not called removeView() when the RecyclerView.Adapter called notifyDataSetChanged()

    opened by android9527 0
  • a issue found in as v1.3

    a issue found in as v1.3

    java.lang.ClassFormatError: Code attribute in native or abstract methods in class file app/mosn/zdepthshadowlayout/shadow/Shadow at java.lang.ClassLoader.defineClass1(Native Method) at java.lang.ClassLoader.defineClass(ClassLoader.java:800) at java.lang.ClassLoader.defineClass(ClassLoader.java:643) at com.android.tools.idea.rendering.RenderClassLoader.defineClassAndPackage(RenderClassLoader.java:211) at com.android.tools.idea.rendering.RenderClassLoader.loadClassFromJar(RenderClassLoader.java:91) at org.jetbrains.android.uipreview.ModuleClassLoader.loadClassFromModuleOrDependency(ModuleClassLoader.java:153) at org.jetbrains.android.uipreview.ModuleClassLoader.load(ModuleClassLoader.java:134) at com.android.tools.idea.rendering.RenderClassLoader.findClass(RenderClassLoader.java:54) at org.jetbrains.android.uipreview.ModuleClassLoader.findClass(ModuleClassLoader.java:86) at java.lang.ClassLoader.loadClass(ClassLoader.java:425) at java.lang.ClassLoader.loadClass(ClassLoader.java:358) at app.mosn.zdepthshadowlayout.ZDepthShadowLayout.onAttachedToWindow(ZDepthShadowLayout.java:81) at android.view.View.dispatchAttachedToWindow(View.java:13525) at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:2688) at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:2695) at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:2695) at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:2695) at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:2695) at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:2695) at android.view.AttachInfo_Accessor.setAttachInfo(AttachInfo_Accessor.java:42) at com.android.layoutlib.bridge.impl.RenderSessionImpl.inflate(RenderSessionImpl.java:422) at com.android.layoutlib.bridge.Bridge.createSession(Bridge.java:321) at com.android.ide.common.rendering.LayoutLibrary.createSession(LayoutLibrary.java:350) at com.android.tools.idea.rendering.RenderTask$2.compute(RenderTask.java:511) at com.android.tools.idea.rendering.RenderTask$2.compute(RenderTask.java:499) at com.intellij.openapi.application.impl.ApplicationImpl.runReadAction(ApplicationImpl.java:888) at com.android.tools.idea.rendering.RenderTask.createRenderSession(RenderTask.java:499) at com.android.tools.idea.rendering.RenderTask.access$600(RenderTask.java:72) at com.android.tools.idea.rendering.RenderTask$3.call(RenderTask.java:611) at com.android.tools.idea.rendering.RenderTask$3.call(RenderTask.java:608) at com.android.tools.idea.rendering.RenderService.runRenderAction(RenderService.java:363) at com.android.tools.idea.rendering.RenderTask.render(RenderTask.java:608) at com.android.tools.idea.rendering.RenderTask.render(RenderTask.java:630) at org.jetbrains.android.uipreview.AndroidLayoutPreviewToolWindowManager.doRender(AndroidLayoutPreviewToolWindowManager.java:645) at org.jetbrains.android.uipreview.AndroidLayoutPreviewToolWindowManager.access$1700(AndroidLayoutPreviewToolWindowManager.java:80) at org.jetbrains.android.uipreview.AndroidLayoutPreviewToolWindowManager$7$1.run(AndroidLayoutPreviewToolWindowManager.java:587) at com.intellij.openapi.progress.impl.CoreProgressManager$2.run(CoreProgressManager.java:152) at com.intellij.openapi.progress.impl.CoreProgressManager.registerIndicatorAndRun(CoreProgressManager.java:452) at com.intellij.openapi.progress.impl.CoreProgressManager.executeProcessUnderProgress(CoreProgressManager.java:402) at com.intellij.openapi.progress.impl.ProgressManagerImpl.executeProcessUnderProgress(ProgressManagerImpl.java:54) at com.intellij.openapi.progress.impl.CoreProgressManager.runProcess(CoreProgressManager.java:137) at org.jetbrains.android.uipreview.AndroidLayoutPreviewToolWindowManager$7.run(AndroidLayoutPreviewToolWindowManager.java:582) at com.intellij.util.ui.update.MergingUpdateQueue.execute(MergingUpdateQueue.java:320) at com.intellij.util.ui.update.MergingUpdateQueue.execute(MergingUpdateQueue.java:310) at com.intellij.util.ui.update.MergingUpdateQueue$2.run(MergingUpdateQueue.java:254) at com.intellij.util.ui.update.MergingUpdateQueue.flush(MergingUpdateQueue.java:269) at com.intellij.util.ui.update.MergingUpdateQueue.flush(MergingUpdateQueue.java:227) at com.intellij.util.ui.update.MergingUpdateQueue.run(MergingUpdateQueue.java:217) at com.intellij.util.concurrency.QueueProcessor.runSafely(QueueProcessor.java:238) at com.intellij.util.Alarm$Request$1.run(Alarm.java:351) at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471) at java.util.concurrent.FutureTask.run(FutureTask.java:262) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) at java.lang.Thread.run(Thread.java:745)

    opened by vegastar002 3
  • multiplying shadows

    multiplying shadows

    When programmatically attaching this view to a ViewGroup, shadows are added but never removed. This quickly results in added but never removed shadows, stacking and darkening the shadow with a poor result.

    Thank you for this library! The solution is explained below:

    public class ZDepthShadowLayout extends FrameLayout { ... onAttachedToWindow() { ... addView(mShadowView, 0); // source of issue ... } ... // START solution to issue onDetachedFromWindow() { super.onDetachedFromWindow(); removeViewAt(0); } // END solution to issue ... }

    opened by ameron32 0
  • Improve legacy code

    Improve legacy code

    This library is legacy code. Latest commit is 3 month ago. https://github.com/ShogoMizumoto/ZDepthShadowLayout/tree/master/ZDepthShadowLayout/src

    My first mission, improve legacy code.

    enhancement 
    opened by sho5nn 0
Releases(1.0.4)
Owner
sho5nn
sho5nn
Provides 9-patch based drop shadow for view elements. Works on API level 9 or later.

Material Shadow 9-Patch This library provides 9-patch based drop shadow for view elements. Works on API level 14 or later. Target platforms API level

Haruki Hasegawa 481 Dec 19, 2022
This is a library with components of Android L to you use in android 2.2

Material Design Android Library How to use Components Buttons Flat Button Rectangle Button Float Button Float small button Switches CheckBox Switch Pr

Ivan Navas 9.1k Jan 5, 2023
📱Android Library to implement animated, 😍beautiful, 🎨stylish Material Dialog in android apps easily.

Material Dialogs for Android ?? ?? Android Library to implement animated, ?? beautiful, ?? stylish Material Dialog in android apps easily. 1. Material

Shreyas Patil 875 Dec 28, 2022
MaterialPickers-in-android - A simple android project that shows how to create material pickers for date and time

MaterialPickers-in-android A simple android project that shows how to create mat

Segun Francis 2 Apr 28, 2022
Material Shadows for android : A library for supporting convex material shadows

MaterialShadows A library for seamlessly integrating Material shadows. The library takes existing material shadows to next level by adding the followi

Harjot Singh Oberai 2.2k Dec 19, 2022
A library to bring fully animated Material Design components to pre-Lolipop Android.

Material MaterialLibrary is an Open Source Android library that back-port Material Design components to pre-Lolipop Android. MaterialLibrary's origina

Rey Pham 6k Dec 21, 2022
😍 A beautiful, fluid, and extensible dialogs API for Kotlin & Android.

Material Dialogs View Releases and Changelogs Modules The core module is the fundamental module that you need in order to use this library. The others

Aidan Follestad 19.5k Dec 31, 2022
The flexible, easy to use, all in one drawer library for your Android project. Now brand new with material 2 design.

MaterialDrawer ... the flexible, easy to use, all in one drawer library for your Android project. What's included ?? • Setup ??️ • Migration Guide ??

Mike Penz 11.6k Dec 27, 2022
Floating Action Button for Android based on Material Design specification

FloatingActionButton Yet another library for drawing Material Design promoted actions. Features Support for normal 56dp and mini 40dp buttons. Customi

Zendesk 6.4k Dec 26, 2022
Implementation of Ripple effect from Material Design for Android API 9+

RippleEffect ExpandableLayout provides an easy way to create a view called header with an expandable view. Both view are external layout to allow a ma

Robin Chutaux 4.9k Dec 30, 2022
Material Design implementation for Android 4.0+. Shadows, ripples, vectors, fonts, animations, widgets, rounded corners and more.

Carbon Material Design implementation for Android 4.0 and newer. This is not the exact copy of the Lollipop's API and features. It's a custom implemen

null 3k Jan 9, 2023
Animations for Android L drawer, back, dismiss and check icons

Material Menu Morphing Android menu, back, dismiss and check buttons Have full control of the animation: Including in your project compile 'com.balysv

Balys Valentukevicius 2.5k Jan 3, 2023
Android L Ripple effect wrapper for Views

Material Ripple Layout Ripple effect wrapper for Android Views Including in your project compile 'com.balysv:material-ripple:1.0.2' Check for latest v

Balys Valentukevicius 2.3k Dec 29, 2022
An Android library aimed to get the beautiful CardViews that Google shows at its official design specifications

MaterialList Discontinued This library will not receive any updates, as I do not have the time or knowledge to improve it. If anyone forks it and want

null 1.6k Nov 29, 2022
Android widget for selecting a range of values.

MaterialRangeBar MaterialRangeBar is a fork from https://github.com/edmodo/range-bar that adds some basic material styling, as well as start and end v

null 1.7k Dec 30, 2022
Android drawer icon with material design animation

LDrawer Android drawer icon with material design animation Note Basically same as appcompat_v7 version 21, you can use appcompat_v7 compile 'com.andro

Hasan Keklik 1.4k Dec 25, 2022
[] Android Library that implements Snackbars from Google's Material Design documentation.

DEPRECATED This lib is deprecated in favor of Google's Design Support Library which includes a Snackbar and is no longer being developed. Thanks for a

null 1.5k Dec 16, 2022
A material horizontal calendar view for Android based on RecyclerView

Horizontal Calendar A material horizontal calendar view for Android based on RecyclerView. Installation The library is hosted on jcenter, add this to

Mulham Raee 1.2k Dec 15, 2022
Android Sample Project with Material Design and Toolbar.

AndroidMaterialDesignToolbar -- PROJECT IS NOT SUPPORTED Android Sample Project with Material Design and Toolbar. Project use Appcompat library for ma

kemal selim tekinarslan 713 Nov 11, 2022