RecyclerView laggy scroll bar

When I used the new recycler view, I noticed that the scrollbar is not as fluid as in a regular ScrollView / ListView. It doesn't seem like it recognizes when you scroll the adapter element, but it only changes when a new element / old element appears, so the progress indicator jumps, rather than moving smoothly. This video demonstrates this problem. Is there any way to make it smooth?

My layout:

<android.support.v7.widget.RecyclerView android:id="@+id/listRecycler" android:scrollbars="vertical" android:layout_width="match_parent" android:layout_height="match_parent"/> 

Fragment:

  mListRecycler.setAdapter(mAdapter); LinearLayoutManager layoutManager = new LinearLayoutManager(getActivity()); layoutManager.setOrientation(LinearLayoutManager.VERTICAL); mListRecycler.setLayoutManager(layoutManager); 

Adapter:

 public class NewsAdapter extends RecyclerView.Adapter<NewsAdapter.ViewHolder> { private List<News> items; private int itemLayout; public NewsAdapter(List<News> items, int itemLayout) { this.items = items; this.itemLayout = itemLayout; } @Override public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { View v = LayoutInflater.from(parent.getContext()).inflate(itemLayout, parent, false); v.setOnClickListener(this); return new ViewHolder(v); } @Override public void onBindViewHolder(ViewHolder holder, int position) { News item = items.get(position); holder.text.setText(item.getTitle()); holder.itemView.setTag(item); } @Override public int getItemCount() { return items.size(); } public static class ViewHolder extends RecyclerView.ViewHolder { @InjectView(R.id.title) TextView text; public ViewHolder(View itemView) { super(itemView); ButterKnife.inject(this, itemView); } } 

}

+5
source share
2 answers

This is a problem in the pre-release L. LinearLayoutManager did not have smooth scrolling support . Will be fixed upon release of RecyclerView.

+3
source

RecyclerView also uses the height (if the orientation is vertical or width, if horizontal) to calculate the height (or width) of the scroll bar. If your list item has the same height (or width), consider using setHasFixedSize ().

 mRecyclerList.setHasFixedSize(true); 
0
source

Source: https://habr.com/ru/post/1200384/


All Articles