2015-11-29 44 views
0

下面的ObjectAnimator非常棒。ObjectAnimator從左側屏幕上清除將被遮蓋的圖像

screenWidth = 800; 
ObjectAnimator moveOver = 
      ObjectAnimator.ofInt(localMovingView, "left", screenWidth, 0) 
        .setDuration(500); 
moveOver.start(); 

但是,如果我改變screenWidth從左邊移動,它工作不好。動畫開始時,動畫開始之前的視圖立即消失。新視圖覆蓋了動畫結尾的空白區域。無論是新老觀點已經被添加到不同的ViewGroup

screenWidth = -800; 
ObjectAnimator moveOver = 
      ObjectAnimator.ofInt(localMovingView, "left", screenWidth, 0) 
        .setDuration(500); 
moveOver.start(); 

我無法找到使解決這事ViewGroups,這樣有利於將肯定可以理解的。我檢查了消失的觀點。它有mLeft = 0;

+0

您是否將moveRight應用於消失的視圖,或僅應用了新視圖? –

+0

我只將ObjectAnimator應用於正在移動到屏幕上的新視圖。之前的觀點應該保持在屏幕上,直到動畫結束,此時舊視圖將完全覆蓋。 –

+0

我編輯我的問題更清晰。 –

回答

1

當動畫視圖的位置時,最好調整屬性translationX和translationY。這些屬性並不是絕對的,它們與視圖當前的X和Y位置有關。

編輯:另外,如果在繼續動畫之前視圖出現在它的目的地片刻之前,那麼我之前的問題之一的答案可能會有用。 FragmentTransaction animation is working but appears glitchy

相關問題