/ShadowLayout

可定制化阴影的万能阴影布局ShadowLayout 2.0 震撼上线。效果赶超CardView。阴影支持x,y轴偏移,支持阴影扩散程度,支持阴影圆角,支持单边或多边不显示阴影;支持随意更改颜色值,支持随意更改颜色值,支持随意更改颜色值。重要的事情说三遍

Primary LanguageJavaMIT LicenseMIT

万能阴影布局,定制化你要的阴影。 ShadowLayout 2.0震撼上线(需要阴影地方,被它嵌套即可享受阴影,阴影可定制化,效果赶超CardView)

  • 支持定制化阴影
  • 支持随意更改阴影颜色值
  • 支持x,y轴阴影偏移
  • 可随意更改阴影扩散区域
  • 支持阴影圆角属性
  • 支持单边或多边不显示阴影
  • 支持ShadowLayout背景填充颜色,背景圆角随阴影圆角改变

2.1.5 更新功能(转载请注明出处)

  • 修复未渲染时,设置阴影颜色值bug
  • 增加点击状态时,切换阴影背景颜色状态hl_shadowBackColorClicked

效果展示(截图分辨率模糊,真机运行效果赶超CardView)

基础功能展示 各属性展示 随意更改颜色

扫描二维体验效果(下载密码是:123456)


添加依赖

  • 项目build.gradle添加如下
    allprojects {
     	repositories {
     		maven { url 'https://jitpack.io' }
     	}
     }
  • app build.gradle添加如下
    dependencies {
            implementation 'com.github.lihangleo2:ShadowLayout:2.1.5'
    }

使用(你也可以什么属性都不加,使用默认值)

      <com.lihang.ShadowLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:hl_cornerRadius="18dp"
        app:hl_dx="0dp"
        app:hl_dy="0dp"
        app:hl_leftShow="false"
        app:hl_shadowColor="#2aff0000"
	app:hl_shadowBackColor="#fff"
	app:hl_shadowBackColorClicked="#ff0000"
        app:hl_shadowLimit="5dp">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="36dp"
            android:paddingLeft="10dp"
            android:paddingRight="10dp"
	    android:gravity="center"
            android:text="定制化你的阴影"
            android:textColor="#000" />

    </com.lihang.ShadowLayout>

自定义属性

1、圆角属性

  • app:hl_cornerRadius="18dp" 阴影圆角属性(同时如果设置了背景填充色也是背景圆角)

2、阴影扩散程度

  • app:hl_shadowLimit="5dp" 阴影的扩散区域

3、阴影布局背景颜色值

  • app:hl_shadowBackColor="#fff" 阴影布局背景填充色,圆角属性即是阴影圆角

4、阴影的颜色

  • app:hl_shadowColor="#2a000000" 阴影的颜色可以随便改变,透明度的改变可以改变阴影的清晰程度
    特别注意:系统方法,颜色值必须带透明度。如果你不想加透明度,则默认透明度为16%
	//这里是setShadowLayer源码的描述,去掉了部分代码便于理解
	/*
     * The alpha of the shadow will be the paint's alpha if the shadow color is
     * opaque, or the alpha from the shadow color if not.
     */
    public void setShadowLayer(float radius, float dx, float dy, int shadowColor) {
      mShadowLayerRadius = radius;
      mShadowLayerDx = dx;
      mShadowLayerDy = dy;
      mShadowLayerColor = shadowColor;
      nSetShadowLayer(mNativePaint, radius, dx, dy, shadowColor);
    }

5、x轴的偏移量

  • app:hl_dx="0dp" 也可以理解为左右偏移量

6、y轴的偏移量

  • app:hl_dy="0dp" 也可以理解为上下的偏移量

7、阴影的4边可见不可见(与偏移量无关)

  • app:hl_leftShow="false" 左边的阴影不可见,其他3边保持不变

8、ShadowLayout点击时,切换背景颜色值。省了你去创建shape和selector

  • app:hl_shadowBackColorClicked="#ff0000" 不点击状态下,显示hl_shadowBackColor颜色值。点击时切换成hl_shadowBackColorClicked。松开手指后恢复正常

关于作者。

Android工作多年了,一直向往大厂。在前进的道路上是孤独的。如果你在学习的路上也感觉孤独,请和我一起。让我们在学习道路上少些孤独


Licenses

MIT License

Copyright (c) 2019 leo

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.