@Override
protected void applyTransformation(float interpolatedTime, Transformation t) {
float sx = 1.0f;
float sy = 1.0f;
float scale = getScaleFactor();
if (mFromX != 1.0f || mToX != 1.0f) {
sx = mFromX + ((mToX - mFromX) * interpolatedTime);
}
if (mFromY != 1.0f || mToY != 1.0f) {
sy = mFromY + ((mToY - mFromY) * interpolatedTime);
}
//两个方法都是设置缩放到matrix中,sx,sy代表了缩放的倍数,px,py代表缩放的中心。
if (mPivotX == 0 && mPivotY == 0) {
t.getMatrix().setScale(sx, sy);
} else {
t.getMatrix().setScale(sx, sy, scale * mPivotX, scale * mPivotY);
}
}
- 计算公式
- 使用getGlobalVisibleRect()
//获得控件原本的大小和坐标
Rect rect = new Rect();
imageView.getGlobalVisibleRect(rect);
//这两句用于设置控件缩放的起始点
//imageView.setPivotX(0);
//imageView.setPivotY(0);
//开始动画
scaleAnimation = new ScaleAnimation(0, 1.8f, 0, 1.8f);
scaleAnimation.setFillAfter(true);
imageView.startAnimation(scaleAnimation);
//计算出放大后的Rect,由于乘以放大倍数,可能出现小数,所以使用float类型
RectF viewRect = new RectF((rect.left + imageView.getPivotX()) - (imageView.getPivotX()) * imageView.getScaleX(),
(rect.top + imageView.getPivotY()) - (imageView.getPivotY()) * imageView.getScaleY(),
(rect.left + imageView.getPivotX()) + (rect.width() - imageView.getPivotX()) * imageView.getScaleX(),
(rect.top + imageView.getPivotY()) + (rect.height() - imageView.getPivotY()) * imageView.getScaleY());
int[] index = new int[2];
view.getLocationOnScreen(index);
RectF viewRect = new RectF(index[0],
index[1],
index[0] + view.getWidth() * view.getScaleX(),
index[1] + view.getHeight() * view.getScaleY());
网友评论