Change Position Of View After End Of Animation
I develop a widget based on ViewGroup and my problem is that I need to save position of items after the end of animation. I called setFillAfter(true) in my animation object I creat
Solution 1:
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;
Solution 2:
I did it. Here is the code:
privatevoidscrollUp() {
for(inti=0; i < getChildCount(); i++) {
finalViewchild= getChildAt(i);
finalintindex= i;
finalintnewleft= child.getLeft() + mOffsetBetweenItems;
finalintnewTop= child.getTop() - mOffsetBetweenItems;
TranslateAnimationscrollUp=newTranslateAnimation(0, mOffsetBetweenItems, 0, -mOffsetBetweenItems);
scrollUp.setDuration(1500);
scrollUp.setFillEnabled(true);
scrollUp.setAnimationListener(
newAnimationListener() {
@OverridepublicvoidonAnimationStart(Animation animation) {}
@OverridepublicvoidonAnimationRepeat(Animation animation) {}
@OverridepublicvoidonAnimationEnd(Animation animation) {
child.layout(newleft, newTop, newleft + child.getMeasuredWidth(), newTop + child.getMeasuredHeight() );
}
}
);
child.startAnimation(scrollUp);
}
}
Just removed setFillAfter(true)
and write setFillEnabled(true)
instead of. But in this case I don't understand the logic of setFillEnabled()
working, because it provides behavior not like describes in documentation.
Solution 3:
Reverse your animation; Start by giving your view a new position and then animate from the old position to the new position.
Post a Comment for "Change Position Of View After End Of Animation"