在EdgridLayoutManager中平滑滚动

l0oc07j2  于 2021-06-27  发布在  Java
关注(0)|答案(0)|浏览(213)

我找到了如何在stackoverflow上的recycler视图中平滑滚动的答案,其中最常见的答案是 setNestedScrollingEnabled(false) . 但我用的是 StaggeredGridLayoutManager 我面临着同样的问题,即滚动不顺畅,它冻结在一个位置。在我的情况下,将嵌套滚动设置为false没有帮助。我已经看完了这个答案,但与我的问题不符。
在mainactivity的onCreate方法中

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);

我的noteadapter类

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
        }

看看这个:
https://i.stack.imgur.com/x3zjc.gif

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题