sirvon
sirvon

Reputation: 2625

animated fragment jumps to a different spot upon start

I have 2 fragments I am animating one going up and out and one coming in from the left.

The fragment that is displayed first is situated in the center of the canvas.

But when the transaction.setcustomanimation starts the fragment jumps to a spot above its original place and then starts animating.

How can I have the fragment animation begin from where it's originally placed in the center of the screen, instead of jumping to another spot and then animating.

   anim/exit.xml

<objectAnimator xmlns:android="http://schemas.android.com/apk/res/android"
android:propertyName="y"
android:valueType="floatType"
android:valueFrom="0"
android:valueTo="-500"
android:duration="3500"/>

   starting activity

FragmentManager fragmentManager = getFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
fragmentTransaction.setCustomAnimations(R.anim.enter, R.anim.exit);
FragRegister fragRegister = new FragRegister();
fragmentTransaction.replace(R.id.SplashLogo_Fragment, fragRegister, "register");
fragmentTransaction.commit();

Upvotes: 0

Views: 294

Answers (1)

Whitney
Whitney

Reputation: 1237

The values aren't relative to your view. Hence your line android:valueFrom="0" is going to move your fragment first and then animate. Remove that line all together. I only set the valueTo parameter in my objectanimator xml.

Upvotes: 1

Related Questions