From 8a6245d34c54cbb5eb8b96027a1016d5e0db0818 Mon Sep 17 00:00:00 2001 From: Vadik Sirekanyan Date: Wed, 2 May 2018 23:57:16 +0300 Subject: [PATCH] fix scaling when targetWidth or targetHeight is not specified --- .../zoonref/viewbehavior/SimpleViewBehavior.java | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/library/src/main/java/com/zoonref/viewbehavior/SimpleViewBehavior.java b/library/src/main/java/com/zoonref/viewbehavior/SimpleViewBehavior.java index b14262c..e2462e5 100644 --- a/library/src/main/java/com/zoonref/viewbehavior/SimpleViewBehavior.java +++ b/library/src/main/java/com/zoonref/viewbehavior/SimpleViewBehavior.java @@ -108,15 +108,19 @@ void updateViewWithPercent(View child, float percent) { float newX = targetX == UNSPECIFIED_INT ? 0 : (targetX - mStartX) * percent; float newY = targetY == UNSPECIFIED_INT ? 0 : (targetY - mStartY) * percent; - // set scale - if (targetWidth != UNSPECIFIED_INT || targetHeight != UNSPECIFIED_INT) { + // set width scale + if (targetWidth != UNSPECIFIED_INT) { float newWidth = mStartWidth + ((targetWidth - mStartWidth) * percent); - float newHeight = mStartHeight + ((targetHeight - mStartHeight) * percent); - child.setScaleX(newWidth / mStartWidth); - child.setScaleY(newHeight / mStartHeight); // make up position for scale change newX -= (mStartWidth - newWidth) / 2; + } + + // set height scale + if (targetHeight != UNSPECIFIED_INT) { + float newHeight = mStartHeight + ((targetHeight - mStartHeight) * percent); + child.setScaleY(newHeight / mStartHeight); + // make up position for scale change newY -= (mStartHeight - newHeight) / 2; }