- 支持定制化阴影
- 支持随意更改阴影颜色值
- 支持x,y轴阴影偏移
- 可随意更改阴影扩散区域
- 支持阴影圆角属性
- 支持单边或多边不显示阴影
- 支持ShadowLayout背景填充颜色,背景圆角随阴影圆角改变
- 修复未渲染时,设置阴影颜色值bug
- 增加点击状态时,切换阴影背景颜色状态hl_shadowBackColorClicked
基础功能展示 | 各属性展示 | 随意更改颜色 |
---|---|---|
- 项目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>
- app:hl_cornerRadius="18dp" 阴影圆角属性(同时如果设置了背景填充色也是背景圆角)
- app:hl_shadowLimit="5dp" 阴影的扩散区域
- app:hl_shadowBackColor="#fff" 阴影布局背景填充色,圆角属性即是阴影圆角
- 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);
}
- app:hl_dx="0dp" 也可以理解为左右偏移量
- app:hl_dy="0dp" 也可以理解为上下的偏移量
- app:hl_leftShow="false" 左边的阴影不可见,其他3边保持不变
- app:hl_shadowBackColorClicked="#ff0000" 不点击状态下,显示hl_shadowBackColor颜色值。点击时切换成hl_shadowBackColorClicked。松开手指后恢复正常
Android工作多年了,一直向往大厂。在前进的道路上是孤独的。如果你在学习的路上也感觉孤独,请和我一起。让我们在学习道路上少些孤独
- 关于我的经历
- QQ群: 209010674 (点击图标,可以直接加入)
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.