Open pom1004 opened 5 years ago
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.
This has nothing to do with MotionLayout. RecyclerView "recycles" layouts, re-uses them. Try to reset constraints when view is binded instead of providing viewtype per position ( which is inefficient - solves your problem because it prevents reusing views ), it should solve problem with continuous animation.
But if I reset constraints also is it solve my lagging issue as well? Have you checked the video? And how I will reset constraint can you give me a example please. Are you talking to reset by using constrainset @melihaksoy?
About how to reset - yes, right on point, constraint set would solve it easy.
I don't know if it'd solve the frame drops, I didn't really experiment with MotionLayout in RecyclerView. What you can do is get a systrace to see what's causing frame drops. If it's MotionLayout related then you can create a new issue with the information you have 👍.
@Override
public void onBindViewHolder(CustomViewHolder holder, int position) {
ConstraintSet constraintSet = new ConstraintSet();
constraintSet.clone(holder.mainLayout);
constraintSet.clear(holder.iv_recorded_program.getId());
constraintSet.clear(holder.rl_recorded_program_info.getId());
constraintSet.clear(holder.button.getId());
constraintSet.connect(holder.iv_recorded_program.getId(), ConstraintSet.BOTTOM, ConstraintSet.PARENT_ID, ConstraintSet.BOTTOM);
constraintSet.connect(holder.iv_recorded_program.getId(), ConstraintSet.TOP, ConstraintSet.PARENT_ID, ConstraintSet.TOP);
constraintSet.connect(holder.iv_recorded_program.getId(), ConstraintSet.START, ConstraintSet.PARENT_ID, ConstraintSet.START);
constraintSet.connect(holder.iv_recorded_program.getId(), ConstraintSet.END, holder.rl_recorded_program_info.getId(), ConstraintSet.START);
constraintSet.connect(holder.rl_recorded_program_info.getId(), ConstraintSet.BOTTOM, ConstraintSet.PARENT_ID, ConstraintSet.BOTTOM);
constraintSet.connect(holder.rl_recorded_program_info.getId(), ConstraintSet.TOP, ConstraintSet.PARENT_ID, ConstraintSet.TOP);
constraintSet.connect(holder.rl_recorded_program_info.getId(), ConstraintSet.END, holder.button.getId(), ConstraintSet.START);
constraintSet.connect(holder.rl_recorded_program_info.getId(), ConstraintSet.START, holder.iv_recorded_program.getId(), ConstraintSet.END);
constraintSet.connect(holder.button.getId(), ConstraintSet.END, ConstraintSet.PARENT_ID, ConstraintSet.END);
constraintSet.connect(holder.button.getId(), ConstraintSet.TOP, ConstraintSet.PARENT_ID, ConstraintSet.TOP);
constraintSet.applyTo(holder.mainLayout);
}
In this way I tried to reset my layout also I removed the position but layout lag & repetation issue not solved.
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:I have posted the whole project in Github and also created a sample video.
For quick gist of motion layout here is the link. And here is the layout desc link.