离子 - 图像无法加载到recyclerview

时间:2015-06-03 21:29:34

标签: android android-recyclerview ion

我一直把头发拉过这个虫子,因为它不能完全重现。我有一个自定义的回收器适配器,它从数据库加载值。它调用网络助手类来构建URL并使用Ion加载图像。此错误似乎不受滚动速度的影响,但我认为它可能会受到同时对服务器进行的图像调用量的影响。

 public ThreadAdapter(Cursor cursor) {
    super(cursor);
}

@Override
public void onBindViewHolderCursor(RecyclerView.ViewHolder holder, Cursor cursor) {
    ThreadViewHolder threadViewHolder = (ThreadViewHolder)holder;

    networkHelper.getImage(threadViewHolder.image,
            cursor.getString(cursor.getColumnIndex(DbContract.ThreadEntry.COLUMN_THREAD_IMAGE_NAME),
            cursor.getString(cursor.getColumnIndex(DbContract.ThreadEntry.COLUMN_THREAD_IMAGE_EXTENSION))
    );
}


@Override
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
    View view = inflater.from(parent.getContext()).inflate(R.layout.card_thread, parent, false);
    ThreadViewHolder viewHolder = new ThreadViewHolder(view);
    return viewHolder;
}

class ThreadViewHolder extends RecyclerView.ViewHolder{
    public ImageView image;

    public ThreadViewHolder(View itemView) {
        super(itemView);
        image = (ImageView) itemView.findViewById(R.id.thread_image);
    }

}

https://gist.github.com/Shywim/127f207e7248fe48400b

public void getImage(ImageView imageView, String name, String extension){
    if (name != null && extension != null){
        String imageUrl = "example.com/" + name + extension;

        Log.d(LOG_TAG, "Image Url " + imageUrl);
        Ion.with(imageView)
                .fitCenter()
                .placeholder(R.drawable.ic_launcher)
                .error(R.drawable.error)
                .load(imageUrl);
    }else {
        imageView.setImageBitmap(null);
    }
}

它似乎正确构建了URL,只在需要调用某些内容时才调用Ion。我有时会看到占位符图像出现然后消失。我从来没有看到错误图像出现。我认为如果项目A,项目B和项目C都有需要加载的图像并且所有图像都同时出现,那么加载它们的失败的可能性就大于它。

0 个答案:

没有答案