带有翻转 CardView 的 Android RecyclerView

4

我使用RecyclerView提供一个卡片列表,这些卡片可以通过滑动来删除(划掉),这个功能类似于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是被滑动的CardView。backView是应该通过翻转动画替换swipeView的CardView。

当我使用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..... ......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}

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


在结尾处添加了一些日志信息和进一步的解释。 - nordic70
1个回答

1
问题在于SwipeView是RelativeLayout,而BackView是CardView。已添加:final View frontView = swipeView.findViewById(R.id.front_card);

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接