From da9dd5ca0c487b5e81290ed6052a36b74d70768e Mon Sep 17 00:00:00 2001 From: Jake Wharton Date: Sun, 24 Jun 2012 21:41:11 -0700 Subject: [PATCH] Clean up pivot math for scaling. --- .../nineoldandroids/view/animation/AnimatorProxy.java | 4 +++- sample/res/layout/toggles.xml | 10 ++++++++-- .../jakewharton/nineoldandroids/sample/Toggles.java | 9 ++++++++- 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/library/src/com/nineoldandroids/view/animation/AnimatorProxy.java b/library/src/com/nineoldandroids/view/animation/AnimatorProxy.java index d5d6a77..ef3dda2 100644 --- a/library/src/com/nineoldandroids/view/animation/AnimatorProxy.java +++ b/library/src/com/nineoldandroids/view/animation/AnimatorProxy.java @@ -303,7 +303,9 @@ private void transformMatrix(Matrix m, View view) { final float sY = mScaleY; if ((sX != 1.0f) || (sY != 1.0f)) { m.postScale(sX, sY); - m.postTranslate(-pX, -pY); + final float sPX = -(pX / w) * ((sX * w) - w); + final float sPY = -(pY / h) * ((sY * h) - h); + m.postTranslate(sPX, sPY); } m.postTranslate(mTranslationX, mTranslationY); diff --git a/sample/res/layout/toggles.xml b/sample/res/layout/toggles.xml index f60ede3..ee35102 100644 --- a/sample/res/layout/toggles.xml +++ b/sample/res/layout/toggles.xml @@ -67,17 +67,23 @@ android:layout_width="fill_parent" android:orientation="horizontal">