Skip to content

Commit

Permalink
// drawable bounds
Browse files Browse the repository at this point in the history
  • Loading branch information
razerdp committed Feb 13, 2017
1 parent 0b39bc8 commit bd489d8
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ Add the dependency

```xml
dependencies {
compile 'com.github.razerdp:PhotoContents:v1.3'
compile 'com.github.razerdp:PhotoContents:{最新版}' //最新版看上方JitPack标签
}
```

Expand Down
17 changes: 10 additions & 7 deletions lib/src/main/java/razerdp/github/com/widget/PhotoContents.java
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,7 @@ public List<Rect> 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);
}
}
Expand All @@ -520,20 +520,23 @@ public List<Matrix> 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;
}
Expand Down

0 comments on commit bd489d8

Please sign in to comment.