我正在尝试使用平移动画和缩放动画制作动画集,以使视图从其大小/位置移动到另一个视图大小/位置。
我尝试使用 getX/getY 或 getLocationOnScreen 获取位置以提供翻译动画师,但没有运气让第一个视图在动画结束时匹配第二个视图:/
(缩放动画相同)
任何想法 ?
明白了...我的问题是我首先应用了平移动画,并且它弄乱了缩放动画的轴心点。
下面的代码示例仅在 X 上翻译。
View viewFrom = findViewById(R.id.viewA);
View viewTo = findViewById(R.id.viewB);
// Getting delta from center
int delta = (viewTo.getLeft()+Math.round(viewTo.getWidth()*viewTo.getScaleX()))-(viewFrom.getLeft()+Math.round(viewFrom.getWidth()+viewFrom.getScaleX()));
float ratio = viewTo.getScaleX() / viewFrom.getScaleX();
Animation anim = new ScaleAnimation(1.f, ratio, 1.f, ratio, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
AnimationSet animSet = new AnimationSet(true);
animSet.setInterpolator(new DecelerateInterpolator());
animSet.addAnimation(anim);
anim = new TranslateAnimation(0, delta, 0, 0);
animSet.addAnimation(anim);
animSet.setDuration(500);
viewFrom.startAnimation(animSet);