2016-07-15 102 views
2

我的目標是將當前視圖從當前位置(居中)動畫到其父項的頂部邊界。那可能嗎?我已經嘗試下面的代碼,但問題是,我認爲動畫後消失:Android查看頂級父項的動畫

Animation bottomUp = AnimationUtils.loadAnimation(context, R.anim.bottom_up); 
popup.startAnimation(bottomUp); 

<set xmlns:android="http://schemas.android.com/apk/res/android"> 
    <translate 
     android:fromYDelta="100%" 
     android:toYDelta="0%" 
     android:fillAfter="true" 
     android:duration="500"/> 
</set> 

回答

1

,可以很容易地在Java中實現與ViewPropertyAnimator

popup.animate().translationY(0).setDuration(500); // 0 is top of Y axis 

的動畫始終從當前位置開始。

檢查ViewPropertyAnimator文件爲未來的動畫,它很容易使用,並可以爲您節省大量的代碼。