Android 回收站是落后的
我的RecyclerView中有8个项目,其中包含一个图像和一个标题。 演出非常滞后 我使用毕加索加载图像。图像的分辨率甚至不高,因此会造成延迟 这是我的适配器:Android 回收站是落后的,android,picasso,android-recyclerview,Android,Picasso,Android Recyclerview,我的RecyclerView中有8个项目,其中包含一个图像和一个标题。 演出非常滞后 我使用毕加索加载图像。图像的分辨率甚至不高,因此会造成延迟 这是我的适配器: public class CategoryAdapter extends RecyclerView.Adapter<CategoryAdapter.CategoryViewHolder> { private Context context; private List<Category> categories;
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();
}
}
公共类CategoryAdapter扩展了RecyclerView.Adapter{
私人语境;
私人名单类别;
类CategoryViewHolder扩展了RecyclerView.ViewHolder{
文本视图类别;
图像视图类别图像;
类别文件夹(视图){
超级(视图);
categoryTitle=(TextView)view.findViewById(R.id.category\u title);
categoryImage=(ImageView)view.findViewById(R.id.category\u缩略图);
}
}
公共类别适配器(上下文、列表类别){
this.context=上下文;
这个。类别=类别;
}
@凌驾
公共类别ViewHolder onCreateViewHolder(视图组父级,int-viewType){
View itemView=LayoutFlater.from(parent.getContext()).flate(R.layout.category_item,parent,false);
返回新的CategoryAdapter.CategoryViewHolder(itemView);
}
@凌驾
BindViewHolder上的公共无效(最终类别ViewHolder,内部位置){
Category=categories.get(位置);
holder.categoryTitle.setText(category.getCategoryTitle());
毕加索。与(上下文)
.load(category.getCategoryImage())
.进入(持有人类别图像);
}
@凌驾
public int getItemCount(){
返回类别。大小();
}
}
您是否为活动设置了背景图像。如果是,请检查背景图像大小。可能是它太大了。一种方法是在从毕加索那里获取图像时异步调用该方法。请查看更多信息中的以下链接我面临着同样的问题,在初始化recyclerview后,这对我来说是有效的,请添加到下面的行中
recyclerView.setNestedScrollingEnabled(false);
使用方法跟踪来确定你在哪里花费时间。是什么让你认为这是回收者视图?这种滞后行为难道不能与获取图像可能需要花费大量时间这一事实联系起来吗?如果你评论掉毕加索的电话,它仍然落后吗?滚动不能落后-毕加索是异步的。你做错了什么elsewhere@Fred我不是通过网络获取图像。它们存储在本地。那么我想问题出在其他地方。。。要么设备太弱,要么代码中存在其他问题。没有背景图像。