Skip to content

Commit

Permalink
fix bug
Browse files Browse the repository at this point in the history
  • Loading branch information
looa committed Aug 8, 2017
1 parent 9f4f7a4 commit 8862f53
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions library/src/main/java/org/looa/view/ViewShadow.java
Original file line number Diff line number Diff line change
Expand Up @@ -108,14 +108,13 @@ private static void createShadowIfNecessary(View view, ShadowData data) {
int width = view.getWidth() + data.shadowRadius * 2 + data.dx * 2;
int height = view.getHeight() + data.shadowRadius * 2 + data.dy * 2;

int top = view.getTop() - data.shadowRadius - data.dy;
int left = view.getLeft() - data.shadowRadius - data.dx;
ViewGroup.LayoutParams layoutParams = new ViewGroup.LayoutParams(width, height);
View vShadow = new View(view.getContext());
data.shadow = vShadow;
vShadow.setLayoutParams(layoutParams);
vShadow.setTranslationX(left);
vShadow.setTranslationY(top);

data.shadow = vShadow;
data.width = width;
data.height = height;

Drawable drawable = view.getBackground();
data.cornerRadius = obtainRadius(drawable);
Expand Down Expand Up @@ -143,10 +142,12 @@ private static void createShadowIfNecessary(View view, ShadowData data) {

private static void trackTargetView(View view, ShadowData data) {
if (data.shadow == null || view == null) return;
int top = (int) (view.getY() - data.shadowRadius - data.dy);
int left = (int) (view.getX() - data.shadowRadius - data.dx);
if (left != data.shadow.getTranslationX()) data.shadow.setTranslationX(left);
int top = view.getTop() - data.shadowRadius - data.dy;
int left = view.getLeft() - data.shadowRadius - data.dx;
top = data.height >= ((ViewGroup) view.getParent()).getHeight() ? 0 : top;
left = data.width >= ((ViewGroup) view.getParent()).getWidth() ? 0 : left;
if (top != data.shadow.getTranslationY()) data.shadow.setTranslationY(top);
if (left != data.shadow.getTranslationX()) data.shadow.setTranslationX(left);
}


Expand All @@ -158,6 +159,7 @@ private static class ShadowData {
int inner;
int color;
int top;
int width, height;

View shadow;

Expand Down

0 comments on commit 8862f53

Please sign in to comment.