1

我正在使用implementation 'androidx.constraintlayout:constraintlayout:2.0.0-alpha4'约束布局的 alpha4。首先,我创建了一个单一的布局并做 onswipe 动画,它与运动布局完美配合,然后我用 recyclerview 修补了布局。现在问题出现了 问题:

  1. 如果我在 rv 的特定项目中进行 onswipe,那么它就会变得滞后。
  2. 假设我现在在 rv 的第一项上滑动,在完全滑动后,你会发现同样的滑动已经发生,第 13 次没有项目,第 25 次没有项目等等。因此,在每 12 项相同的滑动后,您可以在滚动时检查。

我已经在Github上发布了整个项目,还创建了一个示例视频

_在这里快速了解运动布局

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.motion.widget.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"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:layoutDescription="@xml/scene_btn"
    app:showPaths="true"
    >

    <androidx.cardview.widget.CardView
        android:id="@+id/iv_recorded_program"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        app:cardElevation="1dp"
        app:cardCornerRadius="0dp"
        app:layout_constraintEnd_toStartOf="@+id/rl_recorded_program_info"
        app:layout_constraintHorizontal_bias="0.5"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent">

        <ImageView
            style="@style/styleRecordedProgramImage"
            android:layout_width="@dimen/guide_list_width"
            android:layout_height="@dimen/guide_list_height"
            android:visibility="visible"
            />
    </androidx.cardview.widget.CardView>

    <include
        android:id="@+id/rl_recorded_program_info"
        layout="@layout/text"
        android:layout_width="0dp"
        android:layout_height="@dimen/guide_list_height"
        android:background="@color/colorPrimary"
        android:visibility="visible"
        app:layout_constraintEnd_toStartOf="@+id/button"
        app:layout_constraintHorizontal_bias="0.5"
        app:layout_constraintStart_toEndOf="@+id/iv_recorded_program"
        app:layout_constraintTop_toTopOf="parent"/>

    <ImageView
        android:id="@+id/button"
        android:layout_width="0dp"
        android:layout_height="@dimen/guide_list_height"
        android:background="@color/colorAccent"
        android:visibility="visible"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintTop_toTopOf="parent"/>


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

这是布局描述

<?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"
        app:duration="1000">
        <OnSwipe
            app:dragDirection="dragRight"
            app:touchAnchorId="@id/rl_recorded_program_info"
            app:touchAnchorSide="right"/>
    </Transition>


    <ConstraintSet android:id="@+id/start">
        <Constraint
            android:id="@id/iv_recorded_program"
            android:layout_width="@dimen/guide_list_width"
            android:layout_height="@dimen/guide_list_height"
            android:elevation="10dp"
            android:visibility="visible"
            app:layout_constraintEnd_toStartOf="@+id/rl_recorded_program_info"
            app:layout_constraintHorizontal_bias="0.5"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent"/>

        <Constraint
            android:id="@id/rl_recorded_program_info"
            android:layout_width="0dp"
            android:layout_height="@dimen/guide_list_height"
            android:visibility="visible"
            app:layout_constraintEnd_toStartOf="@+id/button"
            app:layout_constraintHorizontal_bias="0.5"
            app:layout_constraintStart_toEndOf="@+id/iv_recorded_program"
            app:layout_constraintTop_toTopOf="parent"/>


        <Constraint
            android:id="@id/button"
            android:layout_width="0dp"
            android:layout_height="@dimen/guide_list_height"
            android:visibility="visible"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintTop_toTopOf="parent"/>

    </ConstraintSet>

    <ConstraintSet android:id="@+id/end">
        <Constraint
            android:id="@id/iv_recorded_program"
            android:layout_width="@dimen/guide_list_width"
            android:layout_height="@dimen/guide_list_height"
            android:elevation="10dp"
            android:visibility="visible"
            app:layout_constraintEnd_toStartOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent"/>

        <Constraint
            android:id="@id/rl_recorded_program_info"
            android:layout_width="0dp"
            android:layout_height="@dimen/guide_list_height"
            app:layout_constraintEnd_toStartOf="@+id/button"
            app:layout_constraintStart_toStartOf="@+id/iv_recorded_program"
            app:layout_constraintTop_toTopOf="parent"/>

        <Constraint
            android:id="@id/button"
            android:layout_width="0dp"
            android:layout_height="@dimen/guide_list_height"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toEndOf="@+id/iv_recorded_program"
            app:layout_constraintTop_toTopOf="parent"/>


    </ConstraintSet>

</MotionScene>
4

1 回答 1

-3

最后,问题由一位同事解决。@Srini 感谢您的解决方案。

 @Override
    public int getItemViewType(int position) {

        return position;
    }

只需要在recyclerview的适配器中重写这个方法。

[注意:]滑动时仍然存在滞后。

于 2019-04-26T09:16:33.603 回答