【发布时间】:2016-02-14 12:25:09
【问题描述】:
我正在使用带有 Gridlayoutmanager 的 RecycleView。当用户向下滚动时,我的应用会加载很多项目。
LinkedList 在添加新元素时具有良好的性能,而我的 ArrayList 需要不断调整大小。
但我不确定 RecycleView 在后台执行的操作会更好地与 ArrayList 和/或 LinkedList 一起使用。
我的适配器是:
public class PhotosAdapter extends RecyclerView.Adapter<PhotosAdapter.PhotosViewHolder> {
private Context context;
private List<Photo> items;
public PhotosAdapter(Context context, List<Photo> items) {
this.context = context;
this.items = items;
}
//other code here
public void addAll(List<Photo> newItems) {
int beforeSize = items.size()-1;
items.addAll(newItems);
notifyItemRangeInserted(beforeSize, newItems.size());
}
}
所以当我创建一个新的空适配器时,我可以这样做:
new PhotosAdapter(getContext(), new ArrayList<Photo>());
或者这个:
new PhotosAdapter(getContext(), new LinkedList<Photo>());
当简单地添加新元素时:
adapter.addAll(myPhotos);
那么在这种情况下,LinkedList 会更好吗? RecycleView 的优化滚动怎么样?使用 ArrayList 还是 LinkedList 效果更好吗?
【问题讨论】:
标签: android performance android-adapter android-recyclerview