【问题标题】:Equivalent of ListView.setEmptyView in RecyclerView等价于 RecyclerView 中的 ListView.setEmptyView
【发布时间】:2014-12-11 02:01:16
【问题描述】:

RecyclerView 中,我想设置一个空视图,以便在适配器为空时显示。是否有 ListView.setEmptyView() 的等价物?

【问题讨论】:

标签: android android-recyclerview


【解决方案1】:

这是一个类似于@dragonborn 的类,但更完整。基于this gist

public class EmptyRecyclerView extends RecyclerView {
    private View emptyView;
    final private AdapterDataObserver observer = new AdapterDataObserver() {
        @Override
        public void onChanged() {
            checkIfEmpty();
        }

        @Override
        public void onItemRangeInserted(int positionStart, int itemCount) {
            checkIfEmpty();
        }

        @Override
        public void onItemRangeRemoved(int positionStart, int itemCount) {
            checkIfEmpty();
        }
    };

    public EmptyRecyclerView(Context context) {
        super(context);
    }

    public EmptyRecyclerView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public EmptyRecyclerView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
    }

    void checkIfEmpty() {
        if (emptyView != null && getAdapter() != null) {
            final boolean emptyViewVisible = getAdapter().getItemCount() == 0;
            emptyView.setVisibility(emptyViewVisible ? VISIBLE : GONE);
            setVisibility(emptyViewVisible ? GONE : VISIBLE);
        }
    }

    @Override
    public void setAdapter(Adapter adapter) {
        final Adapter oldAdapter = getAdapter();
        if (oldAdapter != null) {
            oldAdapter.unregisterAdapterDataObserver(observer);
        }
        super.setAdapter(adapter);
        if (adapter != null) {
            adapter.registerAdapterDataObserver(observer);
        }

        checkIfEmpty();
    }

    public void setEmptyView(View emptyView) {
        this.emptyView = emptyView;
        checkIfEmpty();
    }
}

【讨论】:

  • 你能解释一下我如何使用这个类吗?
  • 就像你对 RecyclerView 所做的一样,它只是添加了setEmptyView 方法,你可以在想要定义空视图时调用它。如果不清楚,请参阅ListView.setEmptyView 文档,这是相同的想法。
  • 很酷的解决方案,但类名很奇怪 =)
  • @AJW 我想这主要取决于您想要实现的目标。两种实现之间的差异非常小,一旦设置了适配器,就没有任何区别了。如果您不更改适配器(很可能是这种情况),则没有区别。
【解决方案2】:

使用新的data binding feature,您还可以直接在布局中实现这一点:

<TextView
   android:text="No data to display."
   android:visibility="@{dataset.size() > 0 ? View.GONE : View.VISIBLE}" />

在这种情况下,您只需向 XML 的数据部分添加一个变量和一个导入:

<data>
<import type="android.view.View"/>
<variable
    name="dataset"
    type="java.util.List&lt;java.lang.String&gt;"
    />
</data>

【讨论】:

  • 为了强调数据绑定方法,上面的例子被简化了。数据绑定非常灵活。您当然可以导入Adapter 而不是数据集并使用其getItemCount() 或将所有内容包装在ViewModel 中并将android:visibility 设置为viewModel.getEmptyViewVisibility()
  • 这个应该更高,它是数据绑定能力的一个很好的例子
  • @javmarina 不,对我来说布局没有继续更新。如果我的适配器从大小 0 开始,然后数据集增长,则布局将不会按需要更新。看来数据绑定对我不起作用。 :-(
  • 即使适配器动态增长或缩小到零,这是否会更新?我对此表示怀疑。
  • @a11n 列表缩小为 0 或获取数据时不会更新布局,每次对列表进行任何更改时,我们都必须从类中为绑定设置值,有没有自己更新布局的方法?
【解决方案3】:

this link 中提供的解决方案似乎很完美。它使用 viewType 来识别何时显示 emptyView。无需创建自定义 RecyclerView

从上面的链接添加代码:

package com.example.androidsampleproject;
import java.util.ArrayList;
import java.util.List;
import android.app.Activity;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

public class RecyclerViewActivity extends Activity {

RecyclerView recyclerView;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_recycler_view);
    recyclerView = (RecyclerView) findViewById(R.id.myList);
    recyclerView.setLayoutManager(new LinearLayoutManager(this));
    recyclerView.setAdapter(new MyAdapter());
}


private class MyAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
    private List<String> dataList = new ArrayList<String>();

    public class EmptyViewHolder extends RecyclerView.ViewHolder {
        public EmptyViewHolder(View itemView) {
            super(itemView);
        }
    }

    public class ViewHolder extends RecyclerView.ViewHolder {
        TextView data;

        public ViewHolder(View v) {
            super(v);
            data = (TextView) v.findViewById(R.id.data_view);
        }
    }

    @Override
    public int getItemCount() {
        return dataList.size() > 0 ? dataList.size() : 1;
    }

    @Override
    public int getItemViewType(int position) {
        if (dataList.size() == 0) {
            return EMPTY_VIEW;
        }
        return super.getItemViewType(position);
    }


    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder vho, final int pos) {
        if (vho instanceof ViewHolder) {
            ViewHolder vh = (ViewHolder) vho;
            String pi = dataList.get(pos);
        }
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View v;

        if (viewType == EMPTY_VIEW) {
            v = LayoutInflater.from(parent.getContext()).inflate(R.layout.empty_view, parent, false);
            EmptyViewHolder evh = new EmptyViewHolder(v);
            return evh;
        }

        v = LayoutInflater.from(parent.getContext()).inflate(R.layout.data_row, parent, false);
        ViewHolder vh = new ViewHolder(v);
        return vh;
    }

    private static final int EMPTY_VIEW = 10;
}

}

【讨论】:

  • 我认为扩展 RecyclerView 是比这个更合适的解决方案,因为通常我有很多回收适配器,我想避免将这种逻辑添加到每个适配器。
  • 这是有道理的@Gunhan,当使用许多回收器适配器时。您也可以尝试扩展为所有常见事物定制的单个 BaseAdapter
  • 即使你只有一个适配器和一个回收者视图,也不是适配器的责任。适配器在这里展示项目,而不是缺少项目。
  • @Kernald 取决于您的用例。就我个人而言,我认为 Sudhasri 这样做的方式要干净得多。特别是如果您想在没有物品的情况下显示不同的视图,例如:“这里没有物品,去购物!”或类似的东西
  • @Deveti Putnik:适配器已经指示没有数据:项目计数等于零。当您使用此解决方案时,您实际上没有提供此信息,因为当适配器为空时,您仍然指示它包含一个元素。这在语义上是错误的。视图类型应该取决于特定元素。没有元素不是元素。使用适配器来处理这种情况意味着您也在使用适配器来处理错误情况。适配器与您丢失网络的事实有什么关系?什么都没有。
【解决方案4】:

我更喜欢简单的解决方案,例如,

让你的 RecyclerView 在 FrameLayout 或 RelativeLayout 与 TextView 或其他视图中显示空数据消息,默认情况下可见性已消失,然后在适配器类中应用逻辑

这里,我有一个 TextView 没有消息数据

@Override
public int getItemCount() {
    textViewNoData.setVisibility(data.size() > 0 ? View.GONE : View.VISIBLE);
    return data.size();
}

【讨论】:

    【解决方案5】:

    如果您想支持更多状态,例如加载状态,错误状态,则可以查看https://github.com/rockerhieu/rv-adapter-states。否则,可以使用来自 (https://github.com/rockerhieu/rv-adapter) 的 RecyclerViewAdapterWrapper 轻松实现支持空视图。这种方法的主要优点是您可以轻松支持空视图,而无需更改现有适配器的逻辑:

    public class StatesRecyclerViewAdapter extends RecyclerViewAdapterWrapper {
        private final View vEmptyView;
    
        @IntDef({STATE_NORMAL, STATE_EMPTY})
        @Retention(RetentionPolicy.SOURCE)
        public @interface State {
        }
    
        public static final int STATE_NORMAL = 0;
        public static final int STATE_EMPTY = 2;
    
        public static final int TYPE_EMPTY = 1001;
    
        @State
        private int state = STATE_NORMAL;
    
        public StatesRecyclerViewAdapter(@NonNull RecyclerView.Adapter wrapped, @Nullable View emptyView) {
            super(wrapped);
            this.vEmptyView = emptyView;
        }
    
        @State
        public int getState() {
            return state;
        }
    
        public void setState(@State int state) {
            this.state = state;
            getWrappedAdapter().notifyDataSetChanged();
            notifyDataSetChanged();
        }
    
        @Override
        public int getItemCount() {
            switch (state) {
                case STATE_EMPTY:
                    return 1;
            }
            return super.getItemCount();
        }
    
        @Override
        public int getItemViewType(int position) {
            switch (state) {
                case STATE_EMPTY:
                    return TYPE_EMPTY;
            }
            return super.getItemViewType(position);
        }
    
        @Override
        public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
            switch (viewType) {
                case TYPE_EMPTY:
                    return new SimpleViewHolder(vEmptyView);
            }
            return super.onCreateViewHolder(parent, viewType);
        }
    
        @Override
        public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
            switch (state) {
                case STATE_EMPTY:
                    onBindEmptyViewHolder(holder, position);
                    break;
                default:
                    super.onBindViewHolder(holder, position);
                    break;
            }
        }
    
        public void onBindEmptyViewHolder(RecyclerView.ViewHolder holder, int position) {
        }
    
        public static class SimpleViewHolder extends RecyclerView.ViewHolder {
            public SimpleViewHolder(View itemView) {
                super(itemView);
            }
        }
    }
    

    用法:

    Adapter adapter = originalAdapter();
    StatesRecyclerViewAdapter statesRecyclerViewAdapter = new StatesRecyclerViewAdapter(adapter, emptyView);
    rv.setAdapter(endlessRecyclerViewAdapter);
    
    // Change the states of the adapter
    statesRecyclerViewAdapter.setState(StatesRecyclerViewAdapter.STATE_EMPTY);
    statesRecyclerViewAdapter.setState(StatesRecyclerViewAdapter.STATE_NORMAL);
    

    【讨论】:

    • 我使用您的代码作为类似解决方案的基础。谢谢!
    【解决方案6】:

    试试RVEmptyObserver:

    这是一个AdapterDataObserver 的实现,它允许您简单地将View 设置为RecylerView 的默认空布局。这样,您无需使用自定义 RecyclerView 并让您的生活变得更加艰难,您可以轻松地将其与现有代码一起使用:


    示例用法:

    RVEmptyObserver observer = new RVEmptyObserver(recyclerView, emptyView)
    rvAdapter.registerAdapterDataObserver(observer);
    

    您可以在此处的实际应用中使用see the codeexample usage


    类:

    public class RVEmptyObserver extends RecyclerView.AdapterDataObserver {
        private View emptyView;
        private RecyclerView recyclerView;
    
        public RVEmptyObserver(RecyclerView rv, View ev) {
            this.recyclerView = rv;
            this.emptyView    = ev;
            checkIfEmpty();
        }
    
        private void checkIfEmpty() {
            if (emptyView != null && recyclerView.getAdapter() != null) {
                boolean emptyViewVisible = recyclerView.getAdapter().getItemCount() == 0;
                emptyView.setVisibility(emptyViewVisible ? View.VISIBLE : View.GONE);
                recyclerView.setVisibility(emptyViewVisible ? View.GONE : View.VISIBLE);
            }
        }
    
        public void onChanged() { checkIfEmpty(); }
        public void onItemRangeInserted(int positionStart, int itemCount) { checkIfEmpty(); }
        public void onItemRangeRemoved(int positionStart, int itemCount) { checkIfEmpty(); }
    }
    

    【讨论】:

      【解决方案7】:

      我的版本,基于https://gist.github.com/adelnizamutdinov/31c8f054d1af4588dc5c

      public class EmptyRecyclerView extends RecyclerView {
          @Nullable
          private View emptyView;
      
          public EmptyRecyclerView(Context context) { super(context); }
      
          public EmptyRecyclerView(Context context, AttributeSet attrs) { super(context, attrs); }
      
          public EmptyRecyclerView(Context context, AttributeSet attrs, int defStyle) {
              super(context, attrs, defStyle);
          }
      
          private void checkIfEmpty() {
              if (emptyView != null && getAdapter() != null) {
                  emptyView.setVisibility(getAdapter().getItemCount() > 0 ? GONE : VISIBLE);
              }
          }
      
          private final AdapterDataObserver observer = new AdapterDataObserver() {
              @Override
              public void onChanged() {
                  checkIfEmpty();
              }
      
              @Override
              public void onItemRangeInserted(int positionStart, int itemCount) {
                  checkIfEmpty();
              }
      
              @Override
              public void onItemRangeRemoved(int positionStart, int itemCount) {
                  checkIfEmpty();
              }
          };
      
          @Override
          public void setAdapter(@Nullable Adapter adapter) {
              final Adapter oldAdapter = getAdapter();
              if (oldAdapter != null) {
                  oldAdapter.unregisterAdapterDataObserver(observer);
              }
              super.setAdapter(adapter);
              if (adapter != null) {
                  adapter.registerAdapterDataObserver(observer);
              }
              checkIfEmpty();
          }
      
          @Override
          public void setVisibility(int visibility) {
              super.setVisibility(visibility);
              if (null != emptyView && (visibility == GONE || visibility == INVISIBLE)) {
                  emptyView.setVisibility(GONE);
              } else {
                  checkIfEmpty();
              }
          }
      
          public void setEmptyView(@Nullable View emptyView) {
              this.emptyView = emptyView;
              checkIfEmpty();
          }
      }
      

      【讨论】:

      • 重新实现setVisibility 的好主意。
      【解决方案8】:

      我希望在 Recycler.Adapter 中实现这个功能

      在您覆盖的 getItemCount 方法上,在此处注入空检查代码:

      @Override
      public int getItemCount() {
          if(data.size() == 0) listIsEmtpy();
          return data.size();
      }
      

      【讨论】:

      • 这不是适配器的责任。适配器在这里展示项目,而不是缺少项目。
      • @Kernald 它是我们的代码和我们自己的方式,我们如何自定义和使用它。
      • @LalitPoptani 当然。但它是一个问答网站,人们在其中寻找答案,大部分时间都没有想到“复制快捷方式又是什么?”。指出解决方案在语义上是错误的(而且当你也有“权利”解决方案时)并不是真的没用......
      • @Kernald 好吧,我认为这个解决方案是最简单的,也是一个很好的解决方案,因为每次通知适配器时都会调用它并且可以用来检查数据的大小!
      • @MarcPlano-Lesay 是正确的。这个答案是不完整的,因为它不处理项目填满后空视图需要不可见的情况。在实施该部分之后,该解决方案变得低效,因为每次适配器查询项目计数时,都会调用setVisibility()。当然你可以添加一些标志来补偿,但那是它变得更加复杂的时候。
      【解决方案9】:

      我已经解决了这个问题:
      创建布局 layout_recyclerview_with_emptytext.xml 文件。
      创建 EmptyViewRecyclerView.java
      ---------

      EmptyViewRecyclerView emptyRecyclerView = (EmptyViewRecyclerView) findViewById(R.id.emptyRecyclerViewLayout);
      emptyRecyclerView.addAdapter(mPrayerCollectionRecyclerViewAdapter, "所选类别没有祈祷。");

      layout_recyclerview_with_emptytext.xml 文件

          <?xml version="1.0" encoding="utf-8"?>
          <merge xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:id="@+id/switcher"
      >
      
      <android.support.v7.widget.RecyclerView
          android:id="@+id/recyclerView"
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          />
      
      <com.ninestars.views.CustomFontTextView android:id="@+id/recyclerViewEmptyTextView"
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:text="Empty Text"
          android:layout_gravity="center"
          android:gravity="center"
          android:textStyle="bold"
          />
      
          </merge>
      


      EmptyViewRecyclerView.java

      public class EmptyViewRecyclerView extends ViewSwitcher {
      private RecyclerView mRecyclerView;
      private CustomFontTextView mRecyclerViewExptyTextView;
      
      public EmptyViewRecyclerView(Context context) {
          super(context);
          initView(context);
      }
      
      public EmptyViewRecyclerView(Context context, AttributeSet attrs) {
          super(context, attrs);
          initView(context);
      }
      
      
      private void initView(Context context) {
          LayoutInflater.from(context).inflate(R.layout.layout_recyclerview_with_emptytext, this, true);
          mRecyclerViewExptyTextView = (CustomFontTextView) findViewById(R.id.recyclerViewEmptyTextView);
          mRecyclerView = (RecyclerView) findViewById(R.id.recyclerView);
          mRecyclerView.setLayoutManager(new LinearLayoutManager(context));
      }
      
      public void addAdapter(final RecyclerView.Adapter<?> adapter) {
          mRecyclerView.setAdapter(adapter);
          adapter.registerAdapterDataObserver(new RecyclerView.AdapterDataObserver() {
              @Override
              public void onChanged() {
                  super.onChanged();
                  if(adapter.getItemCount() > 0) {
                      if (R.id.recyclerView == getNextView().getId()) {
                          showNext();
                      }
                  } else {
                      if (R.id.recyclerViewEmptyTextView == getNextView().getId()) {
                          showNext();
                      }
                  }
              }
          });
      }
      
      public void addAdapter(final RecyclerView.Adapter<?> adapter, String emptyTextMsg) {
          addAdapter(adapter);
          setEmptyText(emptyTextMsg);
      }
      
      public RecyclerView getRecyclerView() {
          return mRecyclerView;
      }
      
      public void setEmptyText(String emptyTextMsg) {
          mRecyclerViewExptyTextView.setText(emptyTextMsg);
      }
      
      }
      

      【讨论】:

        【解决方案10】:
        public class EmptyRecyclerView extends RecyclerView {
          @Nullable View emptyView;
        
          public EmptyRecyclerView(Context context) { super(context); }
        
          public EmptyRecyclerView(Context context, AttributeSet attrs) { super(context, attrs); }
        
          public EmptyRecyclerView(Context context, AttributeSet attrs, int defStyle) {
            super(context, attrs, defStyle);
          }
        
          void checkIfEmpty() {
            if (emptyView != null) {
              emptyView.setVisibility(getAdapter().getItemCount() > 0 ? GONE : VISIBLE);
            }
          }
        
          final @NotNull AdapterDataObserver observer = new AdapterDataObserver() {
            @Override public void onChanged() {
              super.onChanged();
              checkIfEmpty();
            }
          };
        
          @Override public void setAdapter(@Nullable Adapter adapter) {
            final Adapter oldAdapter = getAdapter();
            if (oldAdapter != null) {
              oldAdapter.unregisterAdapterDataObserver(observer);
            }
            super.setAdapter(adapter);
            if (adapter != null) {
              adapter.registerAdapterDataObserver(observer);
            }
          }
        
          public void setEmptyView(@Nullable View emptyView) {
            this.emptyView = emptyView;
            checkIfEmpty();
          }
        }
        

        这样的事情可能会有所帮助

        【讨论】:

        • 这是不完整的。当emptyView 可见时(反之亦然),您可能需要隐藏RecyclerView。您还需要在onItemRangeInserted()onItemRangeRemoved() 上致电checkIfEmpty()。哦,你可以引用你的来源:gist.github.com/adelnizamutdinov/31c8f054d1af4588dc5c
        【解决方案11】:

        我认为 ErrorView 和 EmptyView https://gist.github.com/henrytao-me/2f7f113fb5f2a59987e7 都更完整

        【讨论】:

          【解决方案12】:

          您可以在 RecyclerView 为空时在其上绘制文本。以下自定义子类支持emptyfailedloadingoffline 模式。要成功编译,请将recyclerView_stateText color 添加到您的资源中。

          /**
           * {@code RecyclerView} that supports loading and empty states.
           */
          public final class SupportRecyclerView extends RecyclerView
          {
              public enum State
              {
                  NORMAL,
                  LOADING,
                  EMPTY,
                  FAILED,
                  OFFLINE
              }
          
              public SupportRecyclerView(@NonNull Context context)
              {
                  super(context);
          
                  setUp(context);
              }
          
              public SupportRecyclerView(@NonNull Context context, @Nullable AttributeSet attrs)
              {
                  super(context, attrs);
          
                  setUp(context);
              }
          
              public SupportRecyclerView(@NonNull Context context, @Nullable AttributeSet attrs, int defStyle)
              {
                  super(context, attrs, defStyle);
          
                  setUp(context);
              }
          
              private Paint textPaint;
              private Rect textBounds;
              private PointF textOrigin;
          
              private void setUp(Context c)
              {
                  textPaint = new Paint();
                  textPaint.setAntiAlias(true);
                  textPaint.setColor(ContextCompat.getColor(c, R.color.recyclerView_stateText));
          
                  textBounds = new Rect();
                  textOrigin = new PointF();
              }
          
              private State state;
          
              public State state()
              {
                  return state;
              }
          
              public void setState(State newState)
              {
                  state = newState;
                  calculateLayout(getWidth(), getHeight());
                  invalidate();
              }
          
              private String loadingText = "Loading...";
          
              public void setLoadingText(@StringRes int resId)
              {
                  loadingText = getResources().getString(resId);
              }
          
              private String emptyText = "Empty";
          
              public void setEmptyText(@StringRes int resId)
              {
                  emptyText = getResources().getString(resId);
              }
          
              private String failedText = "Failed";
          
              public void setFailedText(@StringRes int resId)
              {
                  failedText = getResources().getString(resId);
              }
          
              private String offlineText = "Offline";
          
              public void setOfflineText(@StringRes int resId)
              {
                  offlineText = getResources().getString(resId);
              }
          
              @Override
              public void onDraw(Canvas canvas)
              {
                  super.onDraw(canvas);
          
                  String s = stringForCurrentState();
                  if (s == null)
                      return;
          
                  canvas.drawText(s, textOrigin.x, textOrigin.y, textPaint);
              }
          
              private void calculateLayout(int w, int h)
              {
                  String s = stringForCurrentState();
                  if (s == null)
                      return;
          
                  textPaint.setTextSize(.1f * w);
                  textPaint.getTextBounds(s, 0, s.length(), textBounds);
          
                  textOrigin.set(
                   w / 2f - textBounds.width() / 2f - textBounds.left,
                   h / 2f - textBounds.height() / 2f - textBounds.top);
              }
          
              @Override
              protected void onSizeChanged(int w, int h, int oldw, int oldh)
              {
                  super.onSizeChanged(w, h, oldw, oldh);
          
                  calculateLayout(w, h);
              }
          
              private String stringForCurrentState()
              {
                  if (state == State.EMPTY)
                      return emptyText;
                  else if (state == State.LOADING)
                      return loadingText;
                  else if (state == State.FAILED)
                      return failedText;
                  else if (state == State.OFFLINE)
                      return offlineText;
                  else
                      return null;
              }
          }
          

          【讨论】:

            【解决方案13】:

            从我的角度来看,如何创建一个空视图的最简单方法是创建新的空 RecyclerView,并将您想要膨胀的布局作为背景。 当您检查数据集大小时,会设置此空适配器。

            【讨论】:

              【解决方案14】:

              一种更易于使用、更节省资源的空标签设置方法 的 RecyclerView。

              简而言之,引入了一个名为 RecyclerViewEmpty 的新 View。 在它的 onDraw 方法中,如果适配器是空的,它只是绘制一个 Empty Label 在其中心,否则,继续 super.onDraw();

              class RecyclerViewEmpty extends RecyclerView {
                  ....
                  @Override
                  public void onDraw(Canvas canvas) {
                      Adapter a = this.getAdapter();
                      if(a==null || a.getItemCount()<1) {
                          int x= (this.getWidth()-strWidth)>>1;
                          int y = this.getHeight()>>1 ;
                          canvas.drawText(this.emptyLabel, x, y, labelPaint);
                      }
                      else {
                          super.onDraw(canvas);
                      }
                  }
                  ....
              }
              

              详情请参考代码: https://github.com/stzdzyhs/recyclerview-demo

              【讨论】:

              • 虽然此链接可能会回答问题,但最好在此处包含答案的基本部分并提供链接以供参考。如果链接页面发生更改,仅链接答案可能会失效。 - From Review
              • 哎呀,代码思路与@Aleks N. 几乎相同。答案...
              猜你喜欢
              • 1970-01-01
              • 2011-04-25
              • 2015-07-24
              • 1970-01-01
              • 1970-01-01
              • 1970-01-01
              • 2023-04-11
              • 2014-04-14
              相关资源
              最近更新 更多