Android FragmentTransaction setTransitionStyle

I am trying to set up my FragmentTransaction transitions and I came across the setTransitionStyle method. It accepts the xml resource id for the style, but I have no idea what the xml resource will look like. I know that you can define animation styles for actions, and I believe that the xml needed for this method is similar, but I cannot find the documentation in the required format (for example, the xml attributes / nodes needed to do this work).

EDIT1 (this is what I am doing now in my FragmentActivity):

 public void pushFolderFrag(Fragment folderFrag, String backStackID) { FragmentTransaction transaction = getFragmentManager().beginTransaction(); transaction.replace(R.id.SplitView_MasterContainer, folderFrag); transaction.addToBackStack(backStackID); transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_CLOSE); //transaction.setTransitionStyle(arg0);//what does the format for this resource look like?? // Commit the transaction transaction.commit(); } 
+6
source share
2 answers

I found the answer to this link

https://github.com/kedzie/Support_v4_NineOldAndroids

Transition Style Resources

Specify the transition animation in the style resource.

Create a style resource `res / values ​​/styles.xml '

 <?xml version="1.0" encoding="utf-8"?> <resources> <!-- Override standard Transitions with a Style --> <style name="MyTransitionStyle"> <item name="fragmentFadeEnterAnimation">@animator/fade_enter</item> <item name="fragmentFadeExitAnimation">@animator/fade_exit</item> <item name="fragmentOpenEnterAnimation">@animator/flip_left_in</item> <item name="fragmentOpenExitAnimation">@animator/flip_left_out</item> <item name="fragmentCloseEnterAnimation">@animator/flip_right_in</item> <item name="fragmentCloseExitAnimation">@animator/flip_right_out</item> </style> </resources> 

Specify a resource and transition in a transaction

 tx.setTransitionStyle(R.style.MyTransitionStyle); tx.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN); 
+1
source

I know this doesn't exactly answer the question, but why don't you use setCustomAnimations() ?
This call accepts an animation resource if you are using Android 3+ and view the animation if you are using a support package.

0
source

Source: https://habr.com/ru/post/902855/


All Articles