1

I have found the answers for how to make smooth scrolling in Recycler View over stackoverflow, of which the most common answer is to setNestedScrollingEnabled(false). But I am using StaggeredGridLayoutManager and I am facing the same issue i.e. the scrolling is not smooth and it freezes at a position. Setting Nested Scrolling false doesnot help in my case. I have looked through this answer but it does not match my problem.

In my MainActivity's onCreateMethod

        StaggeredGridLayoutManager layoutManager = new StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL);
        layoutManager.setGapStrategy(StaggeredGridLayoutManager.GAP_HANDLING_MOVE_ITEMS_BETWEEN_SPANS);
        recyclerView.setLayoutManager(layoutManager);
        noteAdapter = new NoteAdapter(myList,this);
        recyclerView.setAdapter(noteAdapter);

My NoteAdapter Class

public class NoteAdapter extends RecyclerView.Adapter<NoteAdapter.myAdapter> {

    private List<Note> list;
    private final NotesListeners notesListeners;
    
    public NoteAdapter(List<Note> liste, NotesListeners notesListeners) {
        this.list = liste;
        this.notesListeners = notesListeners;
    }

    @NonNull
    @Override
    public NoteAdapter.myAdapter onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext())
                .inflate(R.layout.item_container_note,parent,
                        false);
        return new myAdapter(view);
    }

    @Override
    public void onBindViewHolder(@NonNull NoteAdapter.myAdapter holder, int position) {
        holder.bind(list.get(position));
        holder.layoutContainer.setOnClickListener(view -> notesListeners.onNoteClicked(list.get(position),position));
    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    @Override
    public int getItemViewType(int position) {
        return position;
    }

    public static class myAdapter extends RecyclerView.ViewHolder {

        TextView textTitle, textSubtitle, textDate;
        LinearLayout layoutContainer;
        RoundedImageView noteImage;

        public myAdapter(@NonNull View itemView) {
            super(itemView);

            //find View By ids here

        }

        public void bind(Note note)
        {
           //Binding few objects
        }


Take a look at this:

https://i.stack.imgur.com/x3zJC.gif

miraquee
  • 181
  • 10

0 Answers0