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