How can I put a container, containing a fragment, inside a ViewPager in order to animate with flip-card effect
<p>I have got a ViewPager with Fragments. Each Fragment consists of an ImageView with front-side of a "card". Swiping shows next (or previous) card. Click on a button gives a random other card. Click on another button should result in a flip-card animation showing the back-side of the card, or if the back-side is shown already, a flip-card animation backwards (same card).
In order to get a flip-card animation, the fragment to be animated must be in a container instead of directly in the viewpager. However, when I try to put a fragment-container (also a fragment) in the viewpager, the whole viewpage mechanism screws up. Normal swiping is not longer possible.</p>

<p>The same / a similar question was asked before:  <a href="https://stackoverflow.com/questions/22171069/how-can-i-animate-a-fragment-inside-a-viewpager?answertab=active#tab-top">https://stackoverflow.com/questions/22171069/how-can-i-animate-a-fragment-inside-a-viewpager?</a>. The accepted answer is not answering my question but shows in the comments that there are more people looking for this answer.</p>

<p>I have browsed a great deal of the internet and I will continue, but I decided to post my question here because most of answers I found for problems came from you, stackoverflow-users!</p>

<p>EDITED to clarify questions in the comments
The animation I want to use works with a container as p.e. specified in:</p>

<pre><code>    &lt;FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:fitsSystemWindows="true"
tools:context="nl.xxx.xxx.xxxActivity"
tools:ignore="MergeRootFrame"&gt;


&lt;LinearLayout
    android:id="@+id/container"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_margin="15dp"
    /&gt;
&lt;/FrameLayout&gt;
</code></pre>

<p>Before animation a fragment with an imageView is added to the container (FrontFragment). Layout of this fragment:</p>

<pre><code>    &lt;ImageView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/imageDisplay"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="16dp"
tools:context="nl.xxx.xxx.xxxActivity" /&gt;
</code></pre>

<p>The animation is (part of the code:)</p>

<pre><code>     mShowingBack = true;

    // Create and commit a new fragment transaction that adds the fragment for the back of
    // the card, uses custom animations, and is part of the fragment manager's back stack.
    BackFragment achterkant= BackFragment.newInstance("blabla");

    getFragmentManager()
            .beginTransaction()

            // Replace the default fragment animations with animator resources representing
            // rotations when switching to the back of the card, as well as animator
            // resources representing rotations when flipping back to the front (e.g. when
            // the system Back button is pressed).
            .setCustomAnimations(
                    R.animator.card_flip_right_in, R.animator.card_flip_right_out,
                    R.animator.card_flip_left_in, R.animator.card_flip_left_out)

            // Replace any fragments currently in the container view with a fragment

            .replace(R.id.container, achterkant)

            // Add this transaction to the back stack, allowing users to press Back
            // to get to the front of the card.
            .addToBackStack(null)

            // Commit the transaction.
            .commit();
</code></pre>

<p>The animations are given in xml-files, for example: card_flip_left_in.xml:</p>

<pre><code>    &lt;set xmlns:android="http://schemas.android.com/apk/res/android"&gt;
&lt;!-- Before rotating, immediately set the alpha to 0. --&gt;
&lt;objectAnimator
    android:valueFrom="1.0"
    android:valueTo="0.0"
    android:propertyName="alpha"
    android:duration="0" /&gt;

&lt;!-- Rotate. --&gt;
&lt;objectAnimator
    android:valueFrom="-180"
    android:valueTo="0"
    android:propertyName="rotationY"
    android:interpolator="@android:interpolator/accelerate_decelerate"
    android:duration="@integer/card_flip_time_full" /&gt;

&lt;!-- Half-way through the rotation (see startOffset), set the alpha to 1. --&gt;
&lt;objectAnimator
    android:valueFrom="0.0"
    android:valueTo="1.0"
    android:propertyName="alpha"
    android:startOffset="@integer/card_flip_time_half"
    android:duration="1" /&gt;
</code></pre>

<p></p>

<p>The code above was duplicated from the internet, and is working perfectly in a non-viewpager situation.</p>