2016-07-27 117 views
1

我有4图像视图我想移动图像1移动和缩放动画的图像2的位置。 [How it looks like图像动画移动和缩放在一起

我已经尝试了缩放

ObjectAnimator scaleX = ObjectAnimator.ofFloat(img1, "scaleX", (float) img2.getWidth()); 
    ObjectAnimator scaleY = ObjectAnimator.ofFloat(img1, "scaleY", (float) img2.getHeight()); 
    scaleX.setDuration(2000); 
    scaleY.setDuration(2000); 
    AnimatorSet scale = new AnimatorSet(); 
    scale.play(scaleX).with(scaleY); 
    scale.start(); 

回答

0

您可以节省大量的代码ViewPropertyAnimator再加上你可以在一个行中组合多个动画:

img1.animate() 
    .scaleX(toX) 
    .scaleY(toY) 
    .translationX(toX) 
    .translationY(toY) 
    .setDuration(2000); 

也有方法:

.scaleXBy(byX) 
.translationYBy(byY) 

th在规模/翻译方法BY给定值

对于你必须记住,翻译:

img2.getX(); 
img2.getY(); 

只给你认为IMG2的左上角的坐标。

你可能想动画到IMG2的中心,将是

img2.getX()/2; 
img2.getY()/2; 

所有的合并这样的事情应该工作:

img1.animate() 
    .scaleX(...) 
    .scaleY(...) 
    .translationX(img2.getX()/2) 
    .translationY(img2.getY()/2) 
    .setDuration(2000); 

编辑:我发现这个页面上的开发者培训网站你可以退房:

Zooming a view

+0

谢谢你r解决方案。但它不起作用。我刚刚检查了文档 - scale mean“设置视图在x轴上的缩放量,作为视图未缩放宽度的一部分,值为1意味着不应用缩放。” – Anirban

+0

那么所有你需要的是scaleX()和scaleY()的其他值,例如scaleX(2)缩放为原始大小的两倍。 –

+0

但是,我怎么能给其他imageview高和宽的价值。 – Anirban