0
我试图从开始矩形(例如由另一个视图定义)缩放视图到它的最终位置。从开始矩形到最终位置的比例
我试图用下面的代码来设置动画看起来直截了当:
float scaleX = 0f;
float scaleY = 0f;
Rect startRect = new Rect(10, 10, 100, 100); // taken from real view position with getLocationOnScreen
final Collection<Animator> animators = new ArrayList<>();
if (animatedView.getMeasuredHeight() != 0) {
scaleX = (float)startRect.width()/animatedView.getMeasuredWidth();
}
if (animatedView.getMeasuredHeight() != 0) {
scaleY = (float)startRect.height()/animatedView.getMeasuredHeight();
}
animatedView.getLocationInWindow(location);
animatedView.setPivotX(startRect.left);
animatedView.setPivotY(startRect.top);
animatedView.setScaleX(scaleX);
animatedView.setScaleY(scaleY);
animators.add(ObjectAnimator.ofFloat(animatedView, View.SCALE_X, 1.0f).setDuration(1000));
animators.add(ObjectAnimator.ofFloat(animatedView, View.SCALE_Y, 1.0f).setDuration(1000));
的animatedView
是RelativeLayout
(下面布局的一些标题视图设置为布局参数)子和测量的宽度和高度,并位置在动画设置时是有效值。
根据startRect
我观察到不同的动画 - 有时动画视图会显示在startRect
的下方或上方。
似乎RectEvaluator是可能的解决方案之一,但它只能从API 18
什么是动画从开始的矩形位置以最终(没有修改的)的正确方法?
使用'android.animation.RectEvaluator' – pskink
@pskink看起来很有希望。我是否应该使用翻译和缩放属性在每个步骤上应用结果矩形? – sandrstar
请参阅http://pastebin.com/jaXTjGjA – pskink