删除项目后 StaggeredGridLayout 管理器,项目分散

StaggeredGridLayout manager after deleting item, items gets scattered

我正在使用交错网格布局从 database.I 向回收者视图显示数据时遇到了一个问题,在从数据库中删除项目以及从适配器中删除位置后,我得到了一些项目渲染 issues.Like散落一地。 这是我的代码

 @Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_note_favorite);
    ButterKnife.bind(this);
    toolbar = (Toolbar) findViewById(R.id.fav_note_toolbar);
    setSupportActionBar(toolbar);

    noteAdapter = new NoteAdapter(noteModelList, NoteFavoriteActivity.this);
    layoutManager = new StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL);
    recyclerView.setLayoutManager(layoutManager);
    recyclerView.setItemAnimator(new DefaultItemAnimator());
    recyclerView.setAdapter(noteAdapter);
    touchListenerRecycler();
    loadDataAll();


}
private void loadAll() {
    noteModelList.clear();

    DBManagerFav dbManagerFav = DBManagerFav.getInstance(NoteFavoriteActivity.this);
    dbManagerFav.openDataBase();
    noteModelList = dbManagerFav.getAllNoteList();
    Log.i(TAG, " size : " + noteModelList.size());
    noteAdapter = new NoteAdapter(noteModelList, NoteFavoriteActivity.this);
    recyclerView.setAdapter(noteAdapter);
    noteAdapter.notifyDataSetChanged();

    dbManagerFav.closeDataBase();

}


 private void deleteOperation() {

    DBManagerFav dbManagerFav = DBManagerFav.getInstance(NoteFavoriteActivity.this);
    dbManagerFav.openDataBase();

    NoteModel noteModel = new NoteModel();
    noteModel.setId(noteModelList.get(adapterClickedPosition).getId());

    int status = dbManagerFav.deleteNote(noteModelList.get(adapterClickedPosition).getId());
    if (status > 0) {

        noteAdapter.removeAt(adapterClickedPosition);

    }
    dbManagerFav.closeDataBase();
    loadDataAll();
}
//this belongs to adapter
public void removeAt(int position) {
    Log.d(TAG, " removing at position : " + position);
    noteModelList.remove(position);
    notifyItemRemoved(position);
    notifyItemRangeChanged(position, noteModelList.size());
    notifyDataSetChanged();
}

附上前后两张截图 在删除项目之前

删除项目后

你能指出我还需要什么吗?

你可以把里面的loadDataAll(){

    layoutManager = new StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL);
    recyclerView.setLayoutManager(layoutManager);

//....... } 瞧..