【发布时间】:2017-07-15 07:06:40
【问题描述】:
我的 RecyclerView 中有 8 个项目,其中包含一个图像和一个标题。 性能非常滞后。
我使用毕加索加载图像。图像甚至没有高分辨率导致延迟。
这是我的适配器:
public class CategoryAdapter extends RecyclerView.Adapter<CategoryAdapter.CategoryViewHolder> {
private Context context;
private List<Category> categories;
class CategoryViewHolder extends RecyclerView.ViewHolder {
TextView categoryTitle;
ImageView categoryImage;
CategoryViewHolder(View view) {
super(view);
categoryTitle = (TextView) view.findViewById(R.id.category_title);
categoryImage = (ImageView) view.findViewById(R.id.category_thumbnail);
}
}
public CategoryAdapter(Context context, List<Category> categories) {
this.context = context;
this.categories = categories;
}
@Override
public CategoryViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View itemView = LayoutInflater.from(parent.getContext()).inflate(R.layout.category_item, parent, false);
return new CategoryAdapter.CategoryViewHolder(itemView);
}
@Override
public void onBindViewHolder(final CategoryViewHolder holder, int position) {
Category category = categories.get(position);
holder.categoryTitle.setText(category.getCategoryTitle());
Picasso.with(context)
.load(category.getCategoryImage())
.into(holder.categoryImage);
}
@Override
public int getItemCount() {
return categories.size();
}
}
【问题讨论】:
-
使用方法跟踪来确定您将时间花在哪里。
-
是什么让你认为这是回收者的观点?延迟行为不能与获取图像可能需要大量时间的事实相关联吗?如果你注释掉毕加索的电话,它仍然滞后吗?
-
滚动不能滞后——毕加索是异步的。你在别处做错了什么
-
@Fred 我没有通过网络获取图像。它们存储在本地。
-
那我猜问题出在其他地方……要么设备太弱,要么代码中存在其他问题。
标签: android picasso android-recyclerview