From bd489d87d3963d15034d4af054ef8a5581840b43 Mon Sep 17 00:00:00 2001 From: razerdp Date: Mon, 13 Feb 2017 17:24:54 +0800 Subject: [PATCH] // drawable bounds --- README.md | 2 +- .../github/com/widget/PhotoContents.java | 17 ++++++++++------- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index e08fac3..e9d03f8 100644 --- a/README.md +++ b/README.md @@ -44,7 +44,7 @@ Add the dependency ```xml dependencies { - compile 'com.github.razerdp:PhotoContents:v1.3' + compile 'com.github.razerdp:PhotoContents:{最新版}' //最新版看上方JitPack标签 } ``` diff --git a/lib/src/main/java/razerdp/github/com/widget/PhotoContents.java b/lib/src/main/java/razerdp/github/com/widget/PhotoContents.java index f67c75f..5b58145 100644 --- a/lib/src/main/java/razerdp/github/com/widget/PhotoContents.java +++ b/lib/src/main/java/razerdp/github/com/widget/PhotoContents.java @@ -499,7 +499,7 @@ public List getContentViewsDrawableRects() { for (int i = 0; i < childCount; i++) { View v = getChildAt(i); if (v != null) { - Rect rect = getDrawableBounds((ImageView) v); + Rect rect = getDrawableBoundsInView((ImageView) v); viewRects.add(rect); } } @@ -520,20 +520,23 @@ public List getContentViewsDrawableMatrixList() { return viewMatrixs; } - private Rect getDrawableBounds(ImageView iv) { + private Rect getDrawableBoundsInView(ImageView iv) { if (iv == null || iv.getDrawable() == null) return null; Drawable d = iv.getDrawable(); Rect result = new Rect(); + iv.getGlobalVisibleRect(result); Rect tDrawableRect = d.getBounds(); Matrix drawableMatrix = iv.getImageMatrix(); float[] values = new float[9]; - drawableMatrix.getValues(values); + if (drawableMatrix != null) { + drawableMatrix.getValues(values); + } - result.left = (int) values[Matrix.MTRANS_X]; - result.top = (int) values[Matrix.MTRANS_Y]; - result.right = (int) (result.left + tDrawableRect.width() * values[Matrix.MSCALE_X]); - result.bottom = (int) (result.top + tDrawableRect.height() * values[Matrix.MSCALE_Y]); + result.left = result.left + (int) values[Matrix.MTRANS_X]; + result.top = result.top + (int) values[Matrix.MTRANS_Y]; + result.right = (int) (result.left + tDrawableRect.width() * (values[Matrix.MSCALE_X] == 0 ? 1.0f : values[Matrix.MSCALE_X])); + result.bottom = (int) (result.top + tDrawableRect.height() * (values[Matrix.MSCALE_Y] == 0 ? 1.0f : values[Matrix.MSCALE_Y])); return result; }