title: Recyclerview initially not scrolling smoothly while loading data from web service
body: <p>I'm using recycler view as a single child inside the swipe refresh layout. Initially, its not scrolling smoothly while loading data from webservice both upwards and downwards. But after first scroll, it scrolls smoothly. How to make it scroll smoothly at very first scroll itself.</p>
  
  <pre><code>    private RecyclerView newsFeedList;
           newsFeedList = (RecyclerView) view.findViewById(R.id.rv_feed_list);
           newsFeedList.setHasFixedSize(true);
                  LinearLayoutManager llm = new LinearLayoutManager(getActivity());
                  llm.setOrientation(LinearLayoutManager.VERTICAL);
                  newsFeedList.setLayoutManager(llm);
  
                  newsFeedAdapter = new NewsFeedAdapter(getActivity(), new ArrayList&lt;NewsFeedParser.NewsFeed&gt;(), newsFeedList);
                  newsFeedList.setAdapter(newsFeedAdapter);
  </code></pre>
  
  <p>and updated recyclerview after getting response from web service by calling below method:</p>
  
  <pre><code>    private void parseDataToNewsFeed(String response, boolean isLoadMore) {
              Gson gson = new Gson();
              NewsFeedParser newsFeedParser = gson.fromJson(response, NewsFeedParser.class);
              if (newsFeedParser.data != null &amp;&amp; newsFeedParser.data.size() &gt; 0) {
                  if (isLoadMore) {
                      newsFeedAdapter.removeProgress(newsFeedAdapter.getItemCount());
                      newsFeedAdapter.addList(newsFeedParser.data);
                  } else {
                      currentPageCount = 1;
                      newsFeedAdapter.updateList(newsFeedParser.data);
                  }
              } else {
                  newsFeedAdapter.updateList(newsFeedParser.data);
                  txtNoResult.setText(getString(R.string.no_clubs_socities_subscribed));
                  txtNoResult.setVisibility(View.VISIBLE);
              }
          }
  </code></pre>
  
  <p>Adaper class:</p>
  
  <pre><code>    public class NewsFeedAdapter extends RecyclerView.Adapter&lt;RecyclerView.ViewHolder&gt; {
                  private final DisplayImageOptions options;
                  private Context context;
                  private ArrayList&lt;NewsFeedParser.NewsFeed&gt; itemList;
                  private int lastVisibleItem, totalItemCount, visibleThreshold = 2;
                  private boolean loading;
                  public OnLoadMoreListener onLoadMoreListener;
                  private OnItemClickListener itemClickListener;
                  //    private ImageLoader mImageLoader;
                  private final int VIEW_ITEM = 1;
                  private final int VIEW_PROG = 0;
                  private long mLastClickTimeListViewItem = 0;
  
                  public NewsFeedAdapter(Context context, ArrayList&lt;NewsFeedParser.NewsFeed&gt; itemList, RecyclerView recyclerView) {
                      this.context = context;
                      this.itemList = itemList;
  
                      options = new DisplayImageOptions.Builder()
                              .showImageOnLoading(R.drawable.ic_default_news)
                              .showImageForEmptyUri(R.drawable.ic_default_news)
                              .showImageOnFail(R.drawable.ic_default_news)
                              .cacheInMemory(true)
                              .cacheOnDisk(true)
                              .considerExifParams(true)
                              .bitmapConfig(Bitmap.Config.RGB_565)
                              .build();
  
                      if (recyclerView.getLayoutManager() instanceof LinearLayoutManager) {
                          final LinearLayoutManager linearLayoutManager = (LinearLayoutManager) recyclerView.getLayoutManager();
                          recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
                              @Override
                              public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
                                  super.onScrolled(recyclerView, dx, dy);
                                  totalItemCount = linearLayoutManager.getItemCount();
                                  lastVisibleItem = linearLayoutManager.findLastVisibleItemPosition();
                                  if (!loading &amp;&amp; totalItemCount &lt;= (lastVisibleItem + visibleThreshold)) {
                                      if (onLoadMoreListener != null) {
                                          onLoadMoreListener.onLoadMore();
                                      }
                                      loading = true;
                                  }
                              }
                          });
                      }
                  }
  
                  @Override
                  public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
                      RecyclerView.ViewHolder vh;
                      if (viewType == VIEW_ITEM) {
                          View itemView = LayoutInflater.from(context).inflate(R.layout.fragment_news_feed_trending_list_item, parent, false);
                          vh = new NewsFeedViewHolder(itemView);
                      } else {
                          View progView = LayoutInflater.from(context).inflate(R.layout.view_refresh_footer, parent, false);
                          vh = new ProgressViewHolder(progView);
                      }
                      return vh;
                  }
  
                  @Override
                  public int getItemViewType(int position) {
                      return itemList.get(position) != null ? VIEW_ITEM : VIEW_PROG;
                  }
  
                  @Override
                  public int getItemCount() {
                      return itemList.size();
                  }
  
                  @Override
                  public void onBindViewHolder(final RecyclerView.ViewHolder holder, final int position) {
                      if (holder instanceof NewsFeedViewHolder) {
                          final NewsFeedParser.NewsFeed singleItem = itemList.get(position);
                          ((NewsFeedViewHolder) holder).txtNews.setText(Html.fromHtml(singleItem.title));
                          ((NewsFeedViewHolder) holder).txtDays.setText(DateConversion.getStatusTiming(context, singleItem.modified));
  
                          ((NewsFeedViewHolder) holder).imgNewsPhoto.setImageResource(R.drawable.ic_default_news);
                          if (singleItem.featured_image != null) {
                              if (singleItem.featured_image.attachment_meta != null) {
                                  if (singleItem.featured_image.attachment_meta.sizes != null) {
                                      if (singleItem.featured_image.attachment_meta.sizes.thumbnail != null) {
                                          if (!TextUtils.isNullOrEmpty(singleItem.featured_image.attachment_meta.sizes.thumbnail.url)) {
                                              ImageLoader.getInstance().displayImage(singleItem.featured_image.attachment_meta.sizes.thumbnail.url, ((NewsFeedViewHolder) holder).imgNewsPhoto, options);
                                          } else {
                                              if (!TextUtils.isNullOrEmpty(singleItem.featured_image.source)) {
                                                  ImageLoader.getInstance().displayImage(singleItem.featured_image.source, ((NewsFeedViewHolder) holder).imgNewsPhoto, options);
                                              }
                                          }
                                      }
                                  }
                              }
                          }
  
                          if (singleItem.read_status == 0) {
                              ((NewsFeedViewHolder) holder).rlFeedItem.setBackgroundColor(ContextCompat.getColor(context, R.color.clr_news_feed_item_bg));
                          } else {
                              ((NewsFeedViewHolder) holder).rlFeedItem.setBackgroundColor(ContextCompat.getColor(context, R.color.transparent));
                          }
  
                          holder.itemView.setOnClickListener(new View.OnClickListener() {
                              @Override
                              public void onClick(View v) {
                                  if (SystemClock.elapsedRealtime() - mLastClickTimeListViewItem &lt; 1000) {
                                      return;
                                  }
                                  mLastClickTimeListViewItem = SystemClock.elapsedRealtime();
                                  if (itemClickListener != null) {
                                      itemClickListener.onItemClick(singleItem);
                                      singleItem.read_status = 1;
                                      notifyItemChanged(position);
                                  }
                              }
                          });
                      } else {
                          ((ProgressViewHolder) holder).progressBar.setLinearProgress(true);
                      }
                  }
  
                  public void addList(ArrayList&lt;NewsFeedParser.NewsFeed&gt; items) {
                      if (items == null) {
                          this.itemList.add(null);
                      } else {
                          for (NewsFeedParser.NewsFeed item : items) {
                              this.itemList.add(item);
                          }
                      }
                      notifyDataSetChanged();
                  }
  
                  public void updateList(ArrayList&lt;NewsFeedParser.NewsFeed&gt; items) {
                      if (items != null) {
                          this.itemList = items;
                      }
                      notifyDataSetChanged();
                  }
  
                  public void removeProgress(int itemCount) {
                      this.itemList.remove(itemCount - 1);
                      notifyItemRemoved(itemCount);
                  }
  
                  public static class NewsFeedViewHolder extends RecyclerView.ViewHolder {
  
                      USUTextView txtNews, txtDays;
                      ImageView imgNewsPhoto;
                      RelativeLayout rlFeedItem;
  
                      public NewsFeedViewHolder(View itemView) {
                          super(itemView);
                          txtNews = (USUTextView) itemView.findViewById(R.id.txt_news);
                          txtDays = (USUTextView) itemView.findViewById(R.id.txt_days);
                          imgNewsPhoto = (ImageView) itemView.findViewById(R.id.img_news_photo);
                          rlFeedItem = (RelativeLayout) itemView.findViewById(R.id.rl_feed_list_item);
                      }
                  }
  
                  public static class ProgressViewHolder extends RecyclerView.ViewHolder {
                      public ProgressWheel progressBar;
  
                      public ProgressViewHolder(View progView) {
                          super(progView);
                          progressBar = (ProgressWheel) progView.findViewById(R.id.progress_bar);
                      }
                  }
  
                  public void setLoaded() {
                      loading = false;
                  }
  
                  public void setOnLoadMoreListener(OnLoadMoreListener onLoadMoreListener) {
                      this.onLoadMoreListener = onLoadMoreListener;
                  }
  
                  public interface OnLoadMoreListener {
                      void onLoadMore();
                  }
  
                  public void setOnItemClickListener(OnItemClickListener recyclerClickListener) {
                      this.itemClickListener = recyclerClickListener;
                  }
  
                  public interface OnItemClickListener {
                      void onItemClick(NewsFeedParser.NewsFeed item);
                  }
              }
  </code></pre>
  
  <p>Please suggest me any idea.....</p>