From 044b14c07ef712800237f0129b0b014d2c23c30a Mon Sep 17 00:00:00 2001 From: Saul M Date: Wed, 26 Aug 2015 00:48:11 +0200 Subject: [PATCH] improved Y values --- .../myapplication/AvatarImageBehavior.java | 30 ++++++++++--------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/app/src/main/java/saulmm/myapplication/AvatarImageBehavior.java b/app/src/main/java/saulmm/myapplication/AvatarImageBehavior.java index f95d0cf..493e404 100644 --- a/app/src/main/java/saulmm/myapplication/AvatarImageBehavior.java +++ b/app/src/main/java/saulmm/myapplication/AvatarImageBehavior.java @@ -44,13 +44,16 @@ public boolean layoutDependsOn(CoordinatorLayout parent, CircleImageView child, return dependency instanceof Toolbar; } - // Child startPosition int startPosition = 0; // Toolbar half position int finalPosition = 0; + int finalHeight = 130; + + int startHeight = 0; + @Override public boolean onDependentViewChanged(CoordinatorLayout parent, CircleImageView child, View dependency) { @@ -61,25 +64,24 @@ public boolean onDependentViewChanged(CoordinatorLayout parent, CircleImageView if (finalPosition == 0) finalPosition = (dependency.getHeight() /2); - CoordinatorLayout.LayoutParams lp = (CoordinatorLayout.LayoutParams) child.getLayoutParams(); + if (startHeight == 0) + startHeight = child.getHeight(); - final int maxNumber = (int) (mMarginTop - getStatusBarHeight()); - // Assume that the final position will be at the top - final int topPosition = 0; + CoordinatorLayout.LayoutParams lp = (CoordinatorLayout.LayoutParams) child.getLayoutParams(); - float currentPositionY = child.getY() + child.getHeight()/2; - float expandedPercentageFactor = dependency.getY() / maxNumber; + final int maxScrollDistance = (int) (mMarginTop - getStatusBarHeight()); + float expandedPercentageFactor = dependency.getY() / maxScrollDistance; + float distanceYToSubtract = ((startPosition - finalPosition) * (1f - expandedPercentageFactor)) + (child.getHeight()/2); + float heightToSubtract = ((startHeight - finalHeight) * (1f - expandedPercentageFactor)); - child.setY(startPosition - (((startPosition - finalPosition) * (1f - expandedPercentageFactor)) + (child.getHeight()/2))); - int proportionalAvatarSize = (int) (mAvatarMaxSize * (expandedPercentageFactor));// -// - if (expandedPercentageFactor >= MIN_AVATAR_PERCENTAGE_SIZE) { - lp.width = proportionalAvatarSize; - lp.height = proportionalAvatarSize; - } + child.setY(startPosition - distanceYToSubtract); + + int proportionalAvatarSize = (int) (mAvatarMaxSize * (expandedPercentageFactor)); + lp.width = (int) (startHeight - heightToSubtract); + lp.height = (int) (startHeight - heightToSubtract); child.setLayoutParams(lp); return true;