RecyclerView慢速滚动

时间:2016-05-19 11:09:49

标签: android android-recyclerview

我正在使用recylcer视图来显示5个预定义项目。 每个项目包含文本和图像。 这就是我加载它们的方式。我也使用Picasso加载图像,但图像甚至没有超过500kb但是当我快速向下滚动时,有一个滞后。任何帮助将不胜感激。

MainActivity中的

List<ItemObject> rowListItem = getAllItemList();
lLayout = new LinearLayoutManager(MainActivity.this);
RecyclerView rView = (RecyclerView)findViewById(R.id.recycler_view);
rView.setLayoutManager(lLayout);
RecyclerViewAdapter rcAdapter = new RecyclerViewAdapter(MainActivity.this, rowListItem);
rView.setAdapter(rcAdapter);

 private List<ItemObject> getAllItemList(){
        List<ItemObject> allItems = new ArrayList<ItemObject>();
        allItems.add(new ItemObject("Add a Task", R.drawable.addtask));
        allItems.add(new ItemObject("Submit Complaint", R.drawable.noelec));
        allItems.add(new ItemObject("View Consumption",R.drawable.statistiw));
        allItems.add(new ItemObject("About Us", R.drawable.aboutus));
        allItems.add(new ItemObject("Track Field Team", R.drawable.ft_track));
        return allItems;
    }

itemObject:

private String name;
    private int photo;

    public ItemObject(String name, int photo) {
        this.name = name;
        this.photo = photo;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getPhoto() {
        return photo;
    }

持有人:

public class RecyclerViewHolders extends RecyclerView.ViewHolder {

    public TextView Name;
    public ImageView Photo;

    public RecyclerViewHolders(View itemView) {
        super(itemView);
        Name = (TextView)itemView.findViewById(R.id.name);
        Photo = (ImageView)itemView.findViewById(R.id.photo);
    }
}

适配器:

public class RecyclerViewAdapter  extends RecyclerView.Adapter<RecyclerViewHolders> {

    private List<ItemObject> itemList;
    private Context context;



    public RecyclerViewAdapter(Context context, List<ItemObject> itemList) {
        this.itemList = itemList;
        this.context = context;
    }

    @Override
    public RecyclerViewHolders onCreateViewHolder(ViewGroup parent, int viewType) {

        View layoutView = LayoutInflater.from(parent.getContext()).inflate(R.layout.card_view_list, null);
        RecyclerViewHolders rcv = new RecyclerViewHolders(layoutView);
        return rcv;
    }

    @Override
    public void onBindViewHolder(RecyclerViewHolders holder, int position) {
        holder.Name.setText(itemList.get(position).getName());
Picasso.with(context).load(itemList.get(position).getPhoto()).into(holder.Photo);

    }

    @Override
    public int getItemCount() {
        return this.itemList.size();
    }
}

2 个答案:

答案 0 :(得分:1)

调用此方法setHasStableIds(true);

答案 1 :(得分:0)

全部关于图像的高度和宽度....我将图像高度更改为700,宽度更改为400,并且滚动顺畅