在recyclerview中预加载视图

时间:2016-05-31 07:14:11

标签: android android-recyclerview android-viewholder

我正在使用视图符号模式使用不同的视图类型进行回收查看。 作为我的观点之一,我有一个graphView和加载时间使我的recyclerview在滚过它时口吃。 我已经尝试在onCreateViewhodler中初始化图形,它给了一点但不够: - (

有没有办法预加载视图或只在某些条件下重新加载?

onCreateViewholder

  @Override
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
    ...
    switch(viewType){

        case 0:{
            ...
            break;
        }
        case 1:{
            View v = inflater.inflate(R.layout.today_graph, parent, false);
            viewHolder = new GraphViewholder(v);
            chart = new TodayChartView (mContext, v);
            chart.createGraph(item);
            break;
        }

onBindViewholder

@Override
public void onBindViewHolder(final RecyclerView.ViewHolder holder, int position) {

    switch (holder.getItemViewType()) {
        case 0: {
            ...
            break;
        }
        case 1: {
            GraphViewholder graphViewholder = (GraphViewholder) holder;
            BindGraphViewHolder(graphViewholder, position, chart);
            break;
        }

BindViewholder

private void BindGraphViewHolder(GraphViewholder holder, int position, TodayChartView chart) {
    if(holder.itemView==null){
        ((ViewGroup)holder.itemView).addView(chart.getView());
    }
}

Viewholder

public static class GraphViewholder extends RecyclerView.ViewHolder {
    public GraphViewholder(View view) {
        super(view);
    }
}

0 个答案:

没有答案