Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android FragmentTransaction setTransitionStyle

I'm trying to customize my FragmentTransaction transitions and I came across the setTransitionStyle method. It takes in an xml resource id for a style, but I have no idea what the xml resource would look like. I know you can define animation styles for activities, and I assume the xml needed for this method is similar, but I can't find any documentation on the required format (e.g. the xml attributes/nodes needed to make this work).

EDIT1 (this is what I'm 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();
}
like image 977
RyanM Avatar asked Dec 01 '11 16:12

RyanM


Video Answer


1 Answers

I found the answer on this link

https://github.com/kedzie/Support_v4_NineOldAndroids

Transition style resources

Specify transition animations in a 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 the resource and transition in the transaction

tx.setTransitionStyle(R.style.MyTransitionStyle);
tx.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
like image 130
arne.jans Avatar answered Oct 17 '22 01:10

arne.jans