Hummel
Hummel

Reputation: 372

Android RecyclerView with flipping CardView

My RecyclerView is providing a list of cards that can be dismissed (swipped), inspired by Android-SwipeToDismis. This part is working.

Now added animation to flip the cards like this.

final AnimatorSet setRightOut = (AnimatorSet) AnimatorInflater.loadAnimator(mActivity, R.animator.flip_right_out);
final AnimatorSet setLeftIn = (AnimatorSet) AnimatorInflater.loadAnimator(mActivity, R.animator.flip_left_in);

setRightOut.setTarget(swipeView);
setLeftIn.setTarget(backView);
setRightOut.start();
setLeftIn.start();

The swipeView is the CardView that is swipped. And the backView is the CardView that should replace the swipeView through the flipping animation.

Everything works fine when I use the swipeView twice. So it flips 360 degrees back to itself. But I do not seem to be able to display anything else.

How do I implement the backView correctly? Below my layout XML.

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:card_view="http://schemas.android.com/apk/res-auto"
        android:id="@+id/card_front"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:descendantFocusability="blocksDescendants"
        card_view:cardElevation="@dimen/card_elevation">

        <LinearLayout ....</LinearLayout>

    </android.support.v7.widget.CardView>

    <android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:card_view="http://schemas.android.com/apk/res-auto"
        android:id="@+id/card_back"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:descendantFocusability="blocksDescendants"
        card_view:cardElevation="@dimen/card_elevation">

        <LinearLayout ....</LinearLayout>

    </android.support.v7.widget.CardView>

</RelativeLayout>

With some further investigation it looks like the view is there, but Alpha = 0. Here some information from the log before triggering the flip animation:

RecyclerFragment﹕ ViewHolder{418f3088 position=1 id=-1, oldPos=-1, pLpos:-1} RecyclerFragment﹕ getBackCard: android.widget.RelativeLayout{418f1ab8 V.E..... ......I. 0,0-0,0} RecyclerFragment﹕ swipeView: android.widget.RelativeLayout{418eda10 V.E...C. ........ 0,-13-480,638} RecyclerFragment﹕ LP: android.widget.RelativeLayout$LayoutParams@418dc2b8 RecyclerFragment﹕ backView: android.widget.RelativeLayout{418f1ab8 V.E..... ......I. 0,0-0,0}

When I touch the swipView after the flip animation, I can drag it and is displays the original CardView turned 180 degrees. which I can flip again, but still nothing is displayed. However nothing is displayed without a touch. Any thoughts are welcome!

Upvotes: 4

Views: 4141

Answers (1)

Hummel
Hummel

Reputation: 372

Issue was that the swipeView was the RelativeLayout and the backView was the CardView. Added; final View frontView = swipeView.findViewById(R.id.front_card);

Upvotes: 1

Related Questions