我正在尝试根据RecyclerView项目状态(“选定” /“未选定”)更改ImageView
(可见/不可见)的可见性,因此,如果选定了该项目,我想制作{{1} },如下图所示:
我编写了以下代码来实现这一点:
ImageView
我的问题:
每次我选择一个项目时, private int selectedItem = 0;
public class ViewHolderFilters extends RecyclerView.ViewHolder implements View.OnClickListener {
CircleImageView img;
CircleImageView selected_effect;
ViewHolderFilters(View itemView) {
super(itemView);
img = itemView.findViewById(R.id._imageView);
selected_effect = itemView.findViewById(R.id.selected_effect);
img.setOnClickListener(this);
}
void onBindView(int position) {
final String s = spacecrafts.get(position);
Glide.with(c)
.asBitmap()
.load(s).centerCrop()
.apply(new RequestOptions().placeholder(R.drawable.transparent_icon))
.into(new CustomTarget<Bitmap>() {
@Override
public void onResourceReady(@NonNull Bitmap resource, @Nullable Transition<? super Bitmap> transition) {
progress.setVisibility(View.GONE);
img.setImageBitmap(setEffectLight(c, resource, getThumbnail(bitmapOriginal)));
}
@Override
public void onLoadCleared(@Nullable Drawable placeholder) {
}
});
if (selected_item == position) {
selected_effect.setVisibility(View.VISIBLE);
} else {
selected_effect.setVisibility(View.INVISIBLE);
}
}
@Override
public void onClick(View view) {
monShaderRecyclerViewClickListener.onClick(view, spacecrafts.get(getAdapterPosition()));
selected_item = getAdapterPosition();
notifyDataSetChanged();
}
}
方法都会带来一个动画,它看起来并不流畅也不美观。
如何禁用动画并更新项目?
答案 0 :(得分:0)
在回收者视图中有一个默认的项目动画器。您可以在视图/片段/活动中创建回收器视图时将其禁用:
((DefaultItemAnimator) recyclerView.getItemAnimator()).setSupportsChangeAnimations(false);