Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>To animate the transition between fragments, or to animate the process of showing or hiding a fragment you use the <code>Fragment Manager</code> to create a <code>Fragment Transaction</code>.</p> <p>Within each Fragment Transaction you can specify in and out animations that will be used for show and hide respectively (or both when replace is used). </p> <p>The following code shows how you would replace a fragment by sliding out one fragment and sliding the other one in it's place.</p> <pre><code>FragmentTransaction ft = getFragmentManager().beginTransaction(); ft.setCustomAnimations(R.anim.slide_in_left, R.anim.slide_out_right); DetailsFragment newFragment = DetailsFragment.newInstance(); ft.replace(R.id.details_fragment_container, newFragment, "detailFragment"); // Start the animated transition. ft.commit(); </code></pre> <p>To achieve the same thing with hiding or showing a fragment you'd simply call <code>ft.show</code> or <code>ft.hide</code>, passing in the Fragment you wish to show or hide respectively.</p> <p>For reference, the XML animation definitions would use the <code>objectAnimator</code> tag. An example of slide_in_left might look something like this:</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;set&gt; &lt;objectAnimator xmlns:android="http://schemas.android.com/apk/res/android" android:propertyName="x" android:valueType="floatType" android:valueFrom="-1280" android:valueTo="0" android:duration="500"/&gt; &lt;/set&gt; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload