小编Khd*_*kls的帖子

在 RecyclerView 中删除项目后重叠视图

删除 RecyclerView 中的项目会导致视图重叠,如此视频 链接

fragment_feed.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">

<android.support.v7.widget.RecyclerView
    android:id="@+id/recyclerView"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:scrollbars="none" />
Run Code Online (Sandbox Code Playgroud)

在适配器中

holder.setIsRecyclable(false);
  ((PostViewHolder) holder).mUsername.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                deleteItem(holder.getAdapterPosition());
            }
        });

void deleteItem(int index) {
    postList.remove(index);
    notifyItemRemoved(index);

}
Run Code Online (Sandbox Code Playgroud)

当我改变notifyItemRemoved(index);notifyDataSetChanged();似乎解决了我的问题,但它的原因删除动画破坏。我试图找到解决方案来解决这个问题,但似乎没有人和我有同样的问题。谢谢回答

编辑

@Override
public void onBindViewHolder(final RecyclerView.ViewHolder holder, final int position) {
    holder.setIsRecyclable(false);
    if (holder instanceof PostViewHolder) {
        Post post = (Post) postList.get(position);
        String type = post.getTypePost();

        // Inflate Layout //
        LayoutInflater inflater = LayoutInflater.from(mContext);


        ((PostViewHolder) holder).mUsername.setOnClickListener(new …
Run Code Online (Sandbox Code Playgroud)

android android-recyclerview

5
推荐指数
1
解决办法
1375
查看次数

标签 统计

android ×1

android-recyclerview ×1