Skip to content

Commit

Permalink
improved Y values
Browse files Browse the repository at this point in the history
  • Loading branch information
saulmm committed Aug 25, 2015
1 parent c638ead commit 044b14c
Showing 1 changed file with 16 additions and 14 deletions.
30 changes: 16 additions & 14 deletions app/src/main/java/saulmm/myapplication/AvatarImageBehavior.java
Original file line number Diff line number Diff line change
Expand Up @@ -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) {

Expand All @@ -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;
Expand Down

0 comments on commit 044b14c

Please sign in to comment.