10

I have started using motion layout for some top bar scrolling, and looks like there is an issue that prevents recycler view from showing updated data. Currently I am using 2.0.0-alpha3 of ConstraintLayout. In the view I have toolbar and 2 tabs that act as filter, lets say filterX and filterY those pass some rx stuff that basically just filters list of items based on the type this is not important because data is filtered properly, thread is correct, data is passed to adapter every time, but when I do scroll my motion layout to top or bottom, from time to time the changes are not reflected in recycler view, they reload after I scroll it a little bit or even touch, its not happening in case of standard ConstraitLayout. Have anyone experienced this and know any solution?

Edit: Layout with motion layout:

<androidx.constraintlayout.motion.widget.MotionLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layoutDescription="@xml/scene_month">

    <androidx.appcompat.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:navigationIcon="@drawable/ic_back"/>

    <TextView
        android:id="@+id/title"
        style="@style/ActivityTitle"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@id/toolbar" />

    <com.example.FilterView
        android:id='@+id/filter_view'
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@android:color/white"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@id/title"/>

    <androidx.recyclerview.widget.RecyclerView
        android:id="@+id/recycler"
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:clipToPadding="false"
        android:paddingBottom="16dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@id/filter_view" />

</androidx.constraintlayout.motion.widget.MotionLayout>

And motion scene

<?xml version="1.0" encoding="utf-8"?>
<MotionScene xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto">

    <Transition
        app:constraintSetEnd="@id/end"
        app:constraintSetStart="@id/start">
        <OnSwipe
            app:dragDirection="dragUp"
            app:touchAnchorId="@id/recycler"
            app:touchAnchorSide="top" />
    </Transition>

    <ConstraintSet android:id="@+id/start">
        <Constraint android:id="@id/title"
            android:text="@string/title"
            android:layout_width="match_parent"
            android:layout_height="48dp"
            android:gravity="center_vertical"
            android:textSize="28sp"
            android:textColor="@color/dark_gray"
            android:fontFamily="@font/rubik_medium"
            android:layout_marginStart="16dp"
            android:layout_marginEnd="16dp"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@id/toolbar">
            <CustomAttribute
                app:attributeName="textSize"
                app:customFloatValue="28"/>
        </Constraint>
    </ConstraintSet>

    <ConstraintSet android:id="@+id/end">
        <Constraint android:id="@id/title"
            android:text="@string/title"
            android:layout_width="match_parent"
            android:layout_height="?actionBarSize"
            android:gravity="center_vertical"
            android:minHeight="?actionBarSize"
            android:textSize="28sp"
            android:textColor="@color/dark_gray"
            android:fontFamily="@font/rubik_regular"
            android:layout_marginStart="72dp"
            android:layout_marginEnd="16dp"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent">
            <CustomAttribute
                app:attributeName="textSize"
                app:customFloatValue="20"/>
        </Constraint>
    </ConstraintSet>

</MotionScene>
user2141889
  • 1,925
  • 5
  • 18
  • 22

4 Answers4

3

RecyclerView.scrollBy(0, 0) as temporary workaround.

Link to these Google Issue Tracker

Samnang CHEA
  • 485
  • 6
  • 8
3

By following the possible solution as discussed here: https://issuetracker.google.com/issues/130386093

adding the tag motion:layoutDuringTransition="honorRequest" to the Transition fixed the issue

Example:

<Transition
    android:id="@+id/myTransition"
    motion:constraintSetEnd="@+id/end"
    motion:constraintSetStart="@+id/start"
    motion:layoutDuringTransition="honorRequest"
    motion:motionInterpolator="linear">
    <OnSwipe
        motion:dragDirection="dragUp"
        motion:onTouchUp="stop"
        motion:touchAnchorId="@+id/swipeRefreshLayout"
        motion:touchAnchorSide="top" />

besides that, can also try to update to newer version, in my case, I'm currently using

implementation 'androidx.constraintlayout:constraintlayout:2.0.0-beta08'
implementation 'androidx.recyclerview:recyclerview:1.2.0-alpha05'

Note: layoutDuringTransition tag only available with beta04 version of constraint layout and above

  • `motion:layoutDuringTransition="honorRequest"` made it to work. Updating versions didn't help though, tried up to latest non-stable versions of ConstraintLayout (2.1.0-alpha2), RecyclerView(1.2.0-beta01) and ViewPager2(1.1.0-alpha01). – Myroslav Kolodii Feb 22 '21 at 20:05
1

For some reason RecyclerView.scrollBy(0, 0) didn't work for me. I am scrolling the whole motion layout to top using below method when there are updates to recyclerView.

motionLayoutView.transitionToStart()

Isanaka
  • 125
  • 1
  • 7
  • I found out that you actually need to scroll it and maybe in an animated manner, so in my case smooth scrolling by 1 pixel helped - `recyclerView.smoothScrollBy(0,1)`. Ugly, but works. – frangulyan Apr 02 '20 at 23:13
0

update to newer version

  implementation 'androidx.constraintlayout:constraintlayout:2.0.0-beta7'

as they fixed that problem as listed with release notes

  • Nested scroll view issues in MotionLayout
  • Transition listener issues with MotionLayout
  • Memory leak in MotionLayout
  • RecyclerView performances
  • Group visibility
  • Padding issues

https://androidstudio.googleblog.com/2020/06/constraintlayout-200-beta-7.html

Mahmoud Mabrok
  • 865
  • 9
  • 17