我有一个带有CircularImageView的recyclerView,我正在使用Picasso将图像从URL加载到imageView中。我也添加了淡入淡出动画。 但是当我快速滚动时,recyclerView会显示先前图像的伪像。
这是我的适配器:
public class CastAdapter extends RecyclerView.Adapter<CastAdapter.CastHolder> {
private List<String> cast;
private Context mContext;
public CastAdapter(List<String> cast, Context mContext) {
this.cast = cast;
this.mContext = mContext;
}
@NonNull
@Override
public CastHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
View view = LayoutInflater.from(mContext).inflate(R.layout.item_movie_cast, viewGroup, false);
return new CastHolder(view);
}
@Override
public void onBindViewHolder(@NonNull CastHolder castHolder, int i) {
String url = TMDB_IMAGE + "w185" + cast.get(i);
Picasso.get().load(url).into(castHolder.target);
}
@Override
public int getItemCount() {
return cast.size();
}
class CastHolder extends RecyclerView.ViewHolder {
private CircleImageView imageView;
private Animation fadeIn;
Target target;
CastHolder(@NonNull View itemView) {
super(itemView);
imageView = itemView.findViewById(R.id.cast);
fadeIn = new AlphaAnimation(0, 1);
fadeIn.setInterpolator(new DecelerateInterpolator());
fadeIn.setDuration(200);
fadeIn.reset();
target = new Target() {
@Override
public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) {
imageView.setImageBitmap(bitmap);
imageView.startAnimation(fadeIn);
}
@Override
public void onBitmapFailed(Exception e, Drawable errorDrawable) {
}
@Override
public void onPrepareLoad(Drawable placeHolderDrawable) {
}
};
}
}
编辑:我尝试禁用该动画,并且工件仍然存在
答案 0 :(得分:0)
您必须为淡入淡出的动画设置一些动画持续时间。由于在该动画结束之前进行滚动,因此即使滚动了它们也可以看到它们。
尝试减少动画。