2016-07-27 44 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