Motionlayout с переработчиком View является шатким

Я использовал представление макулатуры в моей макете движения с ручкой, которая является 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>

Используя следующие файлы, вы можете восстановить проблему. Спасибо за чтение. Любая помощь будет оценена.

3 ответа

Я думаю, что уже слишком поздно, чтобы ответить на этот вопрос, но вы можете попробовать это:

Положить ваши 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>

Наконец исправил эту ошибку в androidx.constraintlayout:constraintlayout 2.0.0-beta4

Я столкнулся с аналогичной проблемой при использовании MotionLayout, чтобы свернуть заголовок. Производительность салфетки была ужасной. Итак, я прочитал комментарий @8KCreativeCommons, в котором говорилось, что это может быть вызвано изменением размера recyclerview.

Установка фиксированной высоты recyclerview вместо 0dp(ограничение совпадения) улучшила производительность прокрутки:

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

В вашем случае вам нужно будет установить фиксированный размер для вашего относительного макета @+id/testId.

Также было бы необходимо удалить layout_constraintBottom_toBottomOf="parent"

Другие вопросы по тегам