4

I used a recycler view in my motion-layout with a handle which is an ImageView.But the first time you want to swipe it up it shakes and goes down and up and doesn't come up.

I tried to play with the attributes but nothing worked.

layout:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity"
    android:id="@+id/root">

    <androidx.constraintlayout.motion.widget.MotionLayout
        android:id="@+id/motionLayout"
        app:layoutDescription="@xml/scene3"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:showPaths="true">
        <ImageView
            android:id="@+id/image"
            android:src="@drawable/ic_launcher_background"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:layout_constraintBottom_toTopOf="@id/testId" />

        <RelativeLayout
            android:id="@+id/testId"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintTop_toBottomOf="parent"
            app:layout_constraintVertical_chainStyle="spread">

            <androidx.recyclerview.widget.RecyclerView
                android:id="@+id/recycler_media_view"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_marginTop="10dp"/>

            <com.google.android.material.floatingactionbutton.FloatingActionButton
                android:id="@+id/media_send_fab"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentEnd="true"
                android:layout_alignParentBottom="true"
                android:layout_margin="16dp"
                android:onClick="sendTheMessages"
                app:fabSize="normal" />
        </RelativeLayout>
    </androidx.constraintlayout.motion.widget.MotionLayout>
</RelativeLayout>

scene3.xml:

<?xml version="1.0" encoding="utf-8"?>
<MotionScene xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:motion="http://schemas.android.com/apk/res-auto">
    <Transition
        motion:constraintSetEnd="@+id/end"
        motion:constraintSetStart="@+id/start"
        motion:duration="300"
        motion:interpolator="linear">
        <OnSwipe
            motion:touchAnchorId="@+id/image"
            motion:touchAnchorSide="bottom"
            motion:dragDirection="dragUp"
            motion:dragScale="5"
            motion:maxVelocity="5000"
            motion:moveWhenScrollAtTop="true" />
    </Transition>
    <ConstraintSet android:id="@+id/start">
        <Constraint
            android:id="@+id/testId"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            motion:layout_constraintBottom_toBottomOf="parent"
            motion:layout_constraintTop_toBottomOf="parent"
            motion:layout_constraintVertical_chainStyle="spread">
        </Constraint>
    </ConstraintSet>
    <ConstraintSet android:id="@+id/end">
        <Constraint
            android:id="@+id/testId"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            motion:layout_constraintBottom_toBottomOf="parent"
            motion:layout_constraintTop_toTopOf="parent"
            motion:layout_constraintVertical_chainStyle="spread">
        </Constraint>
    </ConstraintSet>
</MotionScene>

Using the following files you can regenerate the problem.Thanks for reading.Any help would be appreciated.

Steve Moretz
  • 2,758
  • 1
  • 17
  • 31
  • 3
    I experienced similar effects. If you put a Recyclerview inside of a Motionlayout and drag very slowly on the Recyclerview (onSwipe) the Recyclerview will stutter. This probably only happens, if the size of the RV is changing. It seems like this is a bug, cause they managed to fix that when you scroll/drag fast. – 8K Creative Commons May 13 '19 at 16:30
  • 1
    @8KCreativeCommons I totally gave up using motion layout since this didn't work.Made some alternatives myself they are not as good as google's at least they work. – Steve Moretz May 14 '19 at 05:16
  • @steve I am also facing the similar kind of issue can you please take a look are you facing the same or not? https://stackoverflow.com/questions/55591396/motion-layoutalpha4-issue-with-recyclerview-onswipe-item – Subho Dec 23 '19 at 05:29
  • @Subho Sorry I gave up motionlayout and also the native android.I found them both shaky lol.React Native is what I switched to.(if you want to know) – Steve Moretz Dec 23 '19 at 16:32

2 Answers2

0

finally fixed this bug at androidx.constraintlayout:constraintlayout 2.0.0-beta4

user3316557
  • 171
  • 1
  • 6
  • I am also facing the similar kind of issue can you please take a look are you facing the same or not? https://stackoverflow.com/questions/55591396/motion-layoutalpha4-issue-with-recyclerview-onswipe-item – Subho Dec 27 '19 at 06:47
0

I was facing a similar issue while using MotionLayout to collapse the header. The swipe performance was terrible. So I read @8KCreativeCommons comment saying that this may be caused by the change in the recyclerview size.

Setting a fixed recyclerview height instead of the 0dp(match constraint) improved the swipe performance:

private void setRecyclerViewHeight() {
    DisplayMetrics displayMetrics = new DisplayMetrics();
    getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
    int height = displayMetrics.heightPixels;
    mRecyclerView.getLayoutParams().height = height;
}

In your case, you would have to set a fixed size to your relative layout @+id/testId.

It would also be necessary to remove the layout_constraintBottom_toBottomOf="parent"