diff --git a/README.md b/README.md
index 16eb64d..d086b29 100644
--- a/README.md
+++ b/README.md
@@ -4,7 +4,7 @@
* 博客介绍:[震惊,没想到 Shape 也可以这么写](https://www.jianshu.com/p/1288d8873440)
-* 可以扫码下载 Demo 进行演示或者测试,如果扫码下载不了的,[点击此处可直接下载](https://github.com/getActivity/ShapeView/releases/download/8.2/ShapeView.apk)
+* 可以扫码下载 Demo 进行演示或者测试,如果扫码下载不了的,[点击此处可直接下载](https://github.com/getActivity/ShapeView/releases/download/8.3/ShapeView.apk)
![](picture/demo_code.png)
@@ -47,7 +47,7 @@ android {
dependencies {
// Shape 框架:https://github.com/getActivity/ShapeView
- implementation 'com.github.getActivity:ShapeView:8.2'
+ implementation 'com.github.getActivity:ShapeView:8.3'
}
```
diff --git a/app/build.gradle b/app/build.gradle
index 4437127..9ccaf77 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -8,8 +8,8 @@ android {
minSdkVersion 16
// noinspection ExpiredTargetSdkVersion
targetSdkVersion 28
- versionCode 82
- versionName "8.2"
+ versionCode 83
+ versionName "8.3"
}
// 支持 Java JDK 8
@@ -63,5 +63,5 @@ dependencies {
implementation 'com.github.getActivity:TitleBar:9.5'
// 内存泄漏检测:https://github.com/square/leakcanary
- debugImplementation 'com.squareup.leakcanary:leakcanary-android:2.8.1'
+ debugImplementation 'com.squareup.leakcanary:leakcanary-android:2.9.1'
}
\ No newline at end of file
diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml
index 6121a05..54f1621 100644
--- a/app/src/main/res/layout/activity_main.xml
+++ b/app/src/main/res/layout/activity_main.xml
@@ -211,7 +211,6 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
- android:clickable="true"
android:gravity="center"
android:paddingTop="30dp"
android:paddingBottom="30dp"
@@ -224,6 +223,22 @@
app:shape_shadowSize="10dp"
app:shape_solidColor="#FFFFFF" />
+
+
@@ -946,8 +961,8 @@
android:text="改变线的大小和颜色"
android:textColor="@android:color/black"
android:textSize="14sp"
- app:shape_lineGravity="bottom"
app:shape="line"
+ app:shape_lineGravity="bottom"
app:shape_strokeColor="#ffff00ff"
app:shape_strokeWidth="3dp" />
diff --git a/library/build.gradle b/library/build.gradle
index 242e6e6..ae93603 100644
--- a/library/build.gradle
+++ b/library/build.gradle
@@ -5,8 +5,8 @@ android {
defaultConfig {
minSdkVersion 16
- versionCode 82
- versionName "8.2"
+ versionCode 83
+ versionName "8.3"
}
// 支持 Java JDK 8
diff --git a/library/src/main/java/com/hjq/shape/drawable/ShapeDrawable.java b/library/src/main/java/com/hjq/shape/drawable/ShapeDrawable.java
index aa9c970..5c3d7ac 100644
--- a/library/src/main/java/com/hjq/shape/drawable/ShapeDrawable.java
+++ b/library/src/main/java/com/hjq/shape/drawable/ShapeDrawable.java
@@ -319,6 +319,7 @@ public ShapeDrawable setGradientOrientation(ShapeGradientOrientation orientation
public ShapeDrawable setShadowColor(int color) {
mShapeState.setShadowColor(color);
mPathIsDirty = true;
+ mRectIsDirty = true;
invalidateSelf();
return this;
}
@@ -329,6 +330,7 @@ public ShapeDrawable setShadowColor(int color) {
public ShapeDrawable setShadowSize(int size) {
mShapeState.setShadowSize(size);
mPathIsDirty = true;
+ mRectIsDirty = true;
invalidateSelf();
return this;
}
@@ -339,6 +341,7 @@ public ShapeDrawable setShadowSize(int size) {
public ShapeDrawable setShadowOffsetX(int offsetX) {
mShapeState.setShadowOffsetX(offsetX);
mPathIsDirty = true;
+ mRectIsDirty = true;
invalidateSelf();
return this;
}
@@ -349,6 +352,7 @@ public ShapeDrawable setShadowOffsetX(int offsetX) {
public ShapeDrawable setShadowOffsetY(int offsetY) {
mShapeState.setShadowOffsetY(offsetY);
mPathIsDirty = true;
+ mRectIsDirty = true;
invalidateSelf();
return this;
}
@@ -516,7 +520,8 @@ of the fill (if any) without worrying about blending artifacts.
}
mShadowPaint.setColor(shadowColor);
- mShadowPaint.setMaskFilter(new BlurMaskFilter(mShapeState.mShadowSize, BlurMaskFilter.Blur.NORMAL));
+ // 这里解释一下为什么要阴影大小除以 1.2f,因为如果不这么做会导致阴影显示会超过 View 边界,从而导致出现阴影被截断的效果
+ mShadowPaint.setMaskFilter(new BlurMaskFilter(mShapeState.mShadowSize / 1.2f, BlurMaskFilter.Blur.NORMAL));
} else {
if (mShadowPaint != null) {
@@ -796,12 +801,10 @@ private boolean ensureValidRect() {
final ShapeState st = mShapeState;
- float shadowScale = 1.2f;
-
- float let = bounds.left + inset + mShapeState.mShadowSize * shadowScale;
- float top = bounds.top + inset + mShapeState.mShadowSize * shadowScale;
- float right = bounds.right - inset - mShapeState.mShadowSize * shadowScale;
- float bottom = bounds.bottom - inset - mShapeState.mShadowSize * shadowScale;
+ float let = bounds.left + inset + mShapeState.mShadowSize;
+ float top = bounds.top + inset + mShapeState.mShadowSize;
+ float right = bounds.right - inset - mShapeState.mShadowSize;
+ float bottom = bounds.bottom - inset - mShapeState.mShadowSize;
mRect.set(let, top, right, bottom);
diff --git a/library/src/main/java/com/hjq/shape/drawable/ShapeState.java b/library/src/main/java/com/hjq/shape/drawable/ShapeState.java
index 593074c..1d5fb51 100644
--- a/library/src/main/java/com/hjq/shape/drawable/ShapeState.java
+++ b/library/src/main/java/com/hjq/shape/drawable/ShapeState.java
@@ -172,6 +172,11 @@ private void computeOpacity() {
return;
}
+ if (mShadowSize > 0) {
+ mOpaque = false;
+ return;
+ }
+
if (mStrokeWidth > 0 && !isOpaque(mStrokeColor)) {
mOpaque = false;
return;