美文网首页
Android 按钮阴影

Android 按钮阴影

作者: 初心一点 | 来源:发表于2019-01-25 18:07 被阅读19次
    目前应用对UI要求越来越高,难免会有阴影背景需求
    常用的实现方式

    标准Api实现阴影小结

    1. 21 版本及以上采用elevation 和 translationZ来实现阴影效果,虽然简单,但是局限性还是有的,比如纯色圆角阴影就会切掉部分阴影等
    2. ViewCompat 来兼容 Api实现阴影效果,跟上1点一样,21版本一下是没有阴影效果的
    3. Material Design设计中,也大量使用了阴影的效果,例如:FloatingActionButton、CardView 这些控件,都是默认支持阴影效果的

    其他方法实现阴影

    1. 使用.9制作拉伸阴影背景图 给大家推荐个工具:http://inloop.github.io/shadow4android/
    2. 使用shape制作阴影背景图(多针对纯色阴影背景)
    3. 前面标准Api中有一个控件,FloatingActionButton可查看源码发现,阴影效果是ShadowDrawableWrapper对原本的 Drawable 做一个包装,在外围绘制阴影的效果,可以参考实现同样效果
    • 上述几种实现相对于标准Api兼容性高

    第三方库实现阴影(随便搜了3个库验证了下)

    1. 效果不理想:https://github.com/wangjiegulu/ShadowViewHelper
    2. 效果不理想:https://github.com/Devlight/ShadowLayout
    3. 推荐:https://github.com/zhengcx/ShadowHelper

    参考链接

    1. http://www.jcodecraeer.com/a/opensource/2017/0602/8030.html
    2. https://github.com/lijiankun24/ShadowLayout
    3. https://github.com/JuHonggang/ShadowDrawable
    4. https://juejin.im/post/5ae1ba4d6fb9a07acc116b8d
    5. https://github.com/psaravan/FlexiImageView
    6. https://github.com/dmytrodanylyk/shadow-layout
    7. https://blog.csdn.net/android_programmer/article/details/80308743
    8. 推荐详细阅读一遍:https://juejin.im/post/59f95ddaf265da432c232b5b
    9. https://juejin.im/post/5a93943c5188257a76634c4d
    10. https://juejin.im/post/59f09c3e6fb9a0452724ce09

    相关文章

      网友评论

          本文标题:Android 按钮阴影

          本文链接:https://www.haomeiwen.com/subject/rojvjqtx.html