George
George

Reputation: 3817

Animation not working in FragmentTransaction (Android)

I am getting more and more frustrated with a simple fragment switching, which for some reason does not play any animations.

The Fragment switching itself works and I can see my new fragment. However there is no transition.

Can anyone help me understand why? Here is my fragment transaction code:

public class FullscreenActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_fullscreen);
    }

    @Override
    protected void onResume() {
        super.onResume();

        new Handler().postDelayed(new Runnable() {

            @Override
            public void run() {
                FragmentTransaction transaction = getFragmentManager().beginTransaction();
                transaction.setCustomAnimations(R.anim.slide_out_right, R.anim.slide_out_right);
                transaction.replace(R.id.root, new InitialFragment(),"DDDDD");
                transaction.commit();

            }
        }, 3000L);

    }
}

Here, in slide_out_right.xml, the name is misleading - I've set it to something more basic, to be certain I am not screwing the animation params:

<objectAnimator xmlns:android="http://schemas.android.com/apk/res/android"
    android:valueFrom="0"
    android:valueTo="1"
    android:propertyName="alpha"
    android:duration="@android:integer/config_mediumAnimTime" />

Either way, I see NO effect whatsoever. I tried using setTranstition(FragmentTransiniot.TRANSIT_ALLMOST_ALL_OF_THE_FLAGS), nothing seemed to make any effect.

I am not using fragments via the support library, I am testing on a rooted, Galaxy S with Android 4.1.2.

Upvotes: 0

Views: 1461

Answers (2)

George
George

Reputation: 3817

Answering my own question: As I was not seeing just ANY effect on my fragment, no matter what animations I tried and wrote, I figured something more global was wrong. And the answer was stunningly stupid.

The blasted development phone had animators disabled via 'Development Options' in the Android Settings menu. I am ashamed to write how much it took me to figure this out, but hopefully someone else can benefit from this.

Upvotes: 5

Gordak
Gordak

Reputation: 2070

Change the value of :

android:valueTo="1"

to

android:valueTo="1000"

and

android:propertyName="alpha" 

to

android:propertyName="x"

If you want your fragment to move. I had the same issue with a Samsung Galaxy Tab 2 10.1 under version 4.0.3. The Fragment on which I was applying the animation (moving in x direction) didn't move at all. And once I touch it (the Fragment), it refreshed and moved instanously to the final destination.

Upvotes: 0

Related Questions