How to use motion layout with recyclerview
Asked Answered
C

4

6

trying to use MotionLayout with RecyclerView,

when scrolling up, app is crashing with error:

android.content.res.Resources$NotFoundException: Unable to find resource ID #0xffffffff

fragment layout code is

<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>

and layoutDescription code is:

<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>
Carnet answered 11/3, 2019 at 7:41 Comment(2)
is there a resource with id 0xffffffff in your autogenerated resources file?Phasia
no, this id is not preset in R.javaCarnet
F
2

Add android:nestedScrollingEnabled="false" to your recyclerView

works for me.

Factitive answered 24/8, 2020 at 18:5 Comment(2)
Works for me too, tksPenley
Did not work for me.Alexandraalexandre
D
1
app:moveWhenScrollAtTop="@+id/rv_list"

Vale of app:moveWhenScrollAtTop should be boolean.

Dionedionis answered 30/5, 2019 at 13:2 Comment(0)
F
0

Change

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

to

<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>
Fluctuate answered 11/3, 2019 at 15:51 Comment(0)
A
0

Each ConstraintSet should have Constraint by themselves and you need to specify as many Constraint as you want to change the scene, like if you want to move A and B together with one interaction, you need to specify both of them in one ConstraintSet

Also, I'm not sure what you're trying to achieve, but I think you need to write code like below

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

That means you're targeting rv_list to trigger the action.

Athanasia answered 6/4, 2019 at 4:44 Comment(1)
Also, as you already added viewId in the layout file already, you need to change android:id="@+id/cardView" to android:id="@id/cardView"Athanasia

© 2022 - 2024 — McMap. All rights reserved.