Android: Animation Position Resets After Complete

后端 未结 9 1507
南笙
南笙 2020-11-27 13:30

I\'m using an xml defined animation to slide a view off the screen. The problem is, as soon as the animation completes it resets to its original position. I need to know how

9条回答
  •  执笔经年
    2020-11-27 13:54

    You can use

    fillAfter=true
    fillEnabled=true
    

    your View will'not reset to original position, but if you have some buttons or something else in your view , their position will not change.

    You must use ObjectAnimator , it works from API 11 level . It changes View position automatic,

    here is the example

    ObjectAnimator objectAnimator= ObjectAnimator.ofFloat(mContent_container, "translationX", startX, endX);
    objectAnimator.setDuration(1000);
    objectAnimator.start();
    

    Thanks JUL for his answer

    If your app not found object animator, change the API level from Project -> properties -> Android , than import android.animation.ObjectAnimator;

    Regards Hayk

提交回复
热议问题