如何在Recyclerview中使用动作布局

时间:2019-03-11 07:41:33

标签: android android-recyclerview scroll swipe android-motionlayout

尝试将MotionLayoutRecyclerView一起使用,

向上滚动时,应用崩溃并出现错误:

  

android.content.res.Resources $ NotFoundException:无法找到   资源ID#0xffffffff

片段布局代码为

<android.support.constraint.motion.MotionLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    app:layoutDescription="@xml/collapsing_config_order_details"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    ...

<android.support.v7.widget.CardView
        android:id="@+id/cardView"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginTop="8dp"
        app:layout_constraintEnd_toEndOf="@+id/tv_delivery_type"
        app:layout_constraintStart_toStartOf="@+id/imageView15"
        app:layout_constraintTop_toBottomOf="@+id/view4">

     ...

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

<android.support.v7.widget.RecyclerView
        android:id="@+id/rv_list"
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:layout_marginBottom="8dp"
        android:layout_marginTop="8dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="@+id/cardView"
        app:layout_constraintStart_toStartOf="@+id/cardView"
        app:layout_constraintTop_toBottomOf="@+id/cardView" />

</android.support.constraint.motion.MotionLayout>

和layoutDescription代码为:

<MotionScene xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto">

    <Transition
        app:constraintSetEnd="@id/collapsed"
        app:constraintSetStart="@id/expanded">

        <OnSwipe
            app:dragDirection="dragUp"
            app:touchAnchorSide="top"
            app:moveWhenScrollAtTop="@+id/rv_list" />

    </Transition>

    <ConstraintSet android:id="@+id/expanded"
            android:id="@+id/cardView"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginTop="8dp"
            app:layout_constraintEnd_toEndOf="@+id/tv_delivery_type"
            app:layout_constraintStart_toStartOf="@+id/imageView15"
            app:layout_constraintTop_toBottomOf="@+id/view4" />
    </ConstraintSet>

    <ConstraintSet android:id="@+id/collapsed">
    <Constraint
            android:id="@+id/cardView"
            android:layout_width="0dp"
            android:layout_height="1dp"
            android:layout_marginTop="8dp"
            app:layout_constraintEnd_toEndOf="@+id/tv_delivery_type"
            app:layout_constraintStart_toStartOf="@+id/imageView15"
            app:layout_constraintTop_toBottomOf="@+id/view4" />
    </ConstraintSet>

</MotionScene>

4 个答案:

答案 0 :(得分:1)

android:nestedScrollingEnabled="false"添加到您的recyclerView

为我工作。

答案 1 :(得分:0)

更改

<ConstraintSet android:id="@+id/expanded"
            android:id="@+id/cardView"

<ConstraintSet android:id="@+id/expanded" >
<Constraint android:id="@+id/cardView"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginTop="8dp"
        app:layout_constraintEnd_toEndOf="@+id/tv_delivery_type"
        app:layout_constraintStart_toStartOf="@+id/imageView15"
        app:layout_constraintTop_toBottomOf="@+id/view4" />
</ConstraintSet>

答案 2 :(得分:0)

每个ConstraintSet都应自己拥有Constraint,并且您需要指定任意数量的Constraint来更改场景,例如,如果您要同时移动A和B互动,您需要在一个ConstraintSet

中同时指定它们两者

此外,我不确定您要实现的目标,但是我认为您需要编写如下代码

<OnSwipe
        app:dragDirection="dragUp"
        app:touchAnchorId="@id/rv_list"
        app:touchAnchorSide="top" />

这意味着您以rv_list为目标来触发操作。

答案 3 :(得分:0)

app:moveWhenScrollAtTop="@+id/rv_list"

app的标配:moveWhenScrollAtTop应该为布尔值。