Recyclerview onswipe项的运动布局(alpha4)问题 [英] Motion layout(alpha4) issue with recyclerview onswipe item

查看:61
本文介绍了Recyclerview onswipe项的运动布局(alpha4)问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用约束布局的alpha4 implementation 'androidx.constraintlayout:constraintlayout:2.0.0-alpha4'.首先,我创建了一个布局,并对其进行onswipe动画处理,使其与运动布局完美配合,然后使用recyclerview对布局进行了修补. 现在问题浮出水面了 问题:

I am using alpha4 implementation 'androidx.constraintlayout:constraintlayout:2.0.0-alpha4' of constraint layout. First I created a single layout and do onswipe animation it is working perfectly with motion layout then I patched the layout with a recyclerview. Now problem comes into picture Issue:

  1. 如果我在rv的特定项目中进行刷卡操作,那么它将变得滞后.
  2. 假设我现在正在rv的第一个项目上进行滑动,则在完全滑动后您会发现相同的滑动已发生,第13个没有项目,第25个没有项目,依此类推.因此,每滑动12个项目之后,您就可以在滚动时进行检查.

我已将整个项目发布到 Github ,还创建了一个示例

I have posted the whole project in Github and also created a sample video.

_在此处了解运动布局的快速要点

_For quick gist of motion layout here

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

推荐答案

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

Finally the issue is fixed by one of colleague. @Srini Thanks for the solution.

 @Override
    public int getItemViewType(int position) {

        return position;
    }

只需在recyclerview的适配器中重写此方法.

Just need to override this method in adapter of recyclerview.

[注意:]在滑动时仍然有滞后.

这篇关于Recyclerview onswipe项的运动布局(alpha4)问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆