Android RecyclerView与翻转CardView

时间:2015-03-27 10:53:31

标签: android android-animation android-recyclerview recycler-adapter

我的RecyclerView提供了一张可以被解雇(swipped)的卡片列表,受到Android-SwipeToDismis的启发。这部分正在运作。

现在添加动画来像这样翻转卡片。

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();

swipeView是Swift的CardView。而backView是CardView,它应该通过翻转动画取代swipeView。

当我使用swipeView两次时,一切正常。所以它翻转360度回到自身。但我似乎无法展示任何其他内容。

如何正确实现backView?在我的布局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>

通过进一步的调查,它看起来像是视图,但是Alpha = 0.这里有一些来自日志的信息,然后才触发翻转动画:

RecyclerFragment:ViewHolder {418f3088 position = 1 id = -1,oldPos = -1,pLpos:-1} RecyclerFragment:getBackCard:android.widget.RelativeLayout {418f1ab8 V.E ..... ......我。 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 ..... ......我。 0,0-0,0}

当我在翻转动画后触摸swipView时,我可以将其拖动并显示原始的CardView旋转180度。我可以再次翻转,但仍然没有显示任何内容。但是没有触摸就不会显示任何内容。欢迎任何想法!

1 个答案:

答案 0 :(得分:1)

问题是swipeView是RelativeLayout而backView是CardView。添加; final查看frontView = swipeView.findViewById(R.id.front_card);