3

I have an activity which has a fragment loaded in it's FrameLayout by default. And I have set the fragment's enter and exit transition as follows:

HomeFragment homeFragment = new HomeFragment();
homeFragment.setEnterTransition(enter);
homeFragment.setExitTransition(exit);
getSupportFragmentManager().beginTransaction().replace(R.id.vg_full_container,homeFragment).commitAllowingStateLoss();

But when my activity starts up, the fragment doesn't show any transition. However if I make use of FragmentTransaction's setCustomAnimation(), the fragment animates into the screen. Also the fragments whose loading is triggered by some event such as OnClick() etc., on the same activity, transitions into the screen withsetEnterTransition() and setExitTransition(). But the activity's defaultly loaded fragments don't transition or at least I can't see any transition happening. Also, I have not set any enter and exit transitions on the activity that loads this fragment.

How do I get the defaultly loaded fragments to transition with setEnterTransition() and setExitTransition()?

Following is the transition XML file:

<?xml version="1.0" encoding="utf-8"?>
<transitionSet xmlns:android="http://schemas.android.com/apk/res/android">
   <slide
       android:duration="400"
       android:slideEdge="left" />
   <targets>
       <target android:excludeId="@id/toolbar"/>
       <target android:excludeId="@id/collapsing_toolbar"/>
       <target android:excludeId="@id/transaction_toolbar"/>
       <target android:excludeId="@id/tab_layout"/>
   </targets>
</transitionSet>
Floern
  • 33,559
  • 24
  • 104
  • 119
not_again_stackoverflow
  • 1,285
  • 1
  • 13
  • 27

1 Answers1

1

try this:

getSupportFragmentManager()
    .beginTransaction()
    .replace(R.id.vg_full_container,homeFragment)
    .setCustomAnimations(R.anim.enter, R.anim.exit,
                         R.anim.popenter, R.anim.popexit)
    .commitAllowingStateLoss();

sets animations like this:

Android Left to Right slide animation

Community
  • 1
  • 1
Jaydeep Devda
  • 727
  • 4
  • 18
  • I've tried using `setCustomAnimation()` and it works well. But, if I want to use the Android L's Transition frameworks' `setEnterTransition()` and `setExitTransition()` how do I go about it? It doesn't show any Transitions these functions. – not_again_stackoverflow Jul 14 '16 at 09:45
  • do you want to add animations during in activity transitions or fragment transitions? – Jaydeep Devda Jul 14 '16 at 09:52
  • When my activity starts up, I want the fragment to be transitioned as per my XML. But instead, it just pops up without any transition (in my case slide from left). I know `setCustomAnimations()` will animate my fragment's enter and exit. But I can't specify which views to be transitioned/animated and which views to not to animate using `setCustomAnimations()`. As in, I want some of the views in the fragment to slide from left and others to slide from right. – not_again_stackoverflow Jul 14 '16 at 10:01
  • you can try animations on view only. like : http://www.androidhive.info/2013/06/android-working-with-xml-animations/ – Jaydeep Devda Jul 14 '16 at 10:04