问题
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:
- If I am doing onswipe in a particular item of rv then it's getting lagged.
- Suppose I am doing swipe on the 1st item of the rv now after full swipe you will find that same swiped has already happen with 13th no item, 25th no item and so on. So after every 12 item same swipe you can check while you are scrolling.
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>
And here is the layout description
<?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>
回答1:
Finally the issue is fixed by one of colleague. @Srini Thanks for the solution.
@Override
public int getItemViewType(int position) {
return position;
}
Just need to override this method in adapter of recyclerview.
[Note:]Still the lag is there while swiping.
来源:https://stackoverflow.com/questions/55591396/motion-layoutalpha4-issue-with-recyclerview-onswipe-item