使用recyclerView的Motionlayout不稳定

时间:2018-12-30 10:26:40

标签: android-motionlayout

我在运动布局中使用了一个回收站视图,该视图带有一个ImageView手柄,但是第一次想向上滑动它时,它会摇晃,上下摆动而不会抬起。

我尝试使用属性,但没有任何效果。

布局:

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

使用以下文件,您可以重新生成问题。感谢您的阅读。我们将不胜感激。

2 个答案:

答案 0 :(得分:0)

我认为回答这个问题为时已晚,但是您可以尝试一下:

将您的Recyclerview放在RelativeLayout之外

<?xml version="1.0" encoding="utf-8"?>
<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="0dp"
    android:layout_height="200dp"
    android:adjustViewBounds="true"
    android:contentDescription="@null"
    android:fitsSystemWindows="true"
    android:scaleType="center"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent" />


        <androidx.recyclerview.widget.RecyclerView
            android:id="@+id/recycler_media_view"
            android:layout_width="0dp"
    android:layout_height="0dp"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/city_image"
            app:layout_constraintTop_toBottomOf="@+id/image"/>

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

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

答案 1 :(得分:0)

最终将这个错误修复为androidx.constraintlayout:constraintlayout 2.0.0-beta4