创建RecyclerView以显示一些图像和文本,然后用户可以为RecyclerView的行添加书签。 RecyclerView的图像在宽度和高度上匹配父级将是wrap_content。在点击书签时,适配器在RecyclerView中调用notifydatasetchanged。我的问题是,在调用notifydatasetchanged更改后,RecyclerView按高度闪烁其图像。
@Override
public void onBindViewHolder(RecyclerView.ViewHolder holder, final int position) {
if (holder instanceof VHITEM) {
final VHITEM VHitem = (VHITEM) holder;
Glide.with(mContext)
.load(articleDataList.get(position).SourcePath)
.asBitmap()
.diskCacheStrategy(DiskCacheStrategy.ALL)
.placeholder(R.drawable.defaultimage)
.error(R.drawable.defaultimage)
.dontAnimate()
.into(VHitem.imageViewTagPic);
}
}
OnButton单击
VHItem.imageViewAddRemoveBookmark.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
notifyDataSetChanged(); }
}
RecyclerView配置
LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getActivity());
recyclerView.setLayoutManager(linearLayoutManager);
答案 0 :(得分:1)
尝试在RecyclerView
上使用此功能来限制视图的闪烁。
RecyclerView.ItemAnimator animator = mRecycler.getItemAnimator();
if (animator instanceof SimpleItemAnimator) {
((SimpleItemAnimator) animator).setSupportsChangeAnimations(false);
}
答案 1 :(得分:0)
这不是因为滑行,如果项目数据改变了调用notifyitemchanged(position,payload)然后覆盖onBindViewHolder 3参数方法