新しいスレッドでロードロジックを移動しようとしましたが、RecyclerImageViewHolderのImageViewが非常に速く変化します。エラーがRecyclerView
という方法で行うことです、それはRecyclerImageViewHolder新しいスレッドでアイテムをロード
//One view - one thread
private Thread imageLoadThread = null;
public AuthorRecyclerViewHolder(LinearLayout itemView, Activity activity) {
super(itemView);
this.view = itemView;
itemView.findViewById(R.id.card_view).setOnClickListener(this);
this.activity = activity;
}
public AuthorRecyclerViewHolder setItem(AuthorObject ao) {
this.ao = ao;
//Find image
iv = (ImageView) view.findViewById(R.id.imageView);
//Clear
if (imageLoadThread != null)
imageLoadThread.interrupt();
iv.clearAnimation();
iv.setImageResource(R.drawable.notfoundmusic);
//Set content
setImageOnItemView(activity, iv, false);
((TextView) view.findViewById(R.id.description)).setText(ao.description);
((TextView) view.findViewById(R.id.head_author)).setText(ao.name);
return this;
}
public void setImageOnItemView(final Activity activity, final ImageView iv, boolean isBigPicture) {
final Animation vis = AnimationUtils.loadAnimation(activity, R.anim.alphavisible);
final ImageResource ir = isBigPicture ? ao.bigImage == null ? ao.smallImage : ao.bigImage : ao.smallImage == null ? ao.bigImage : ao.smallImage;
if (ir != null)
this.imageLoadThread = ir.getImage(this);
else {
iv.setImageResource(R.drawable.notfoundmusic);
iv.startAnimation(vis);
iv.setAlpha(1.0F);
}
}
@Override
public void recieveResource(final @Nullable Bitmap bitmap, final String id) {
final Thread thisThread = Thread.currentThread();
activity.runOnUiThread(new Runnable() {
@Override
public void run() {
final Animation vis = AnimationUtils.loadAnimation(activity, R.anim.alphavisible);
final Animation unvis = AnimationUtils.loadAnimation(activity, R.anim.alphaunvisible);
iv.clearAnimation();
if (thisThread.isInterrupted())
return;
if (id.substring(id.lastIndexOf("_") + 1).equals(String.valueOf(ao.authorId)))
if (bitmap != null) {
new Handler().postDelayed(new Runnable() {
public void run() {
iv.setImageBitmap(bitmap);
iv.setAnimation(vis);
}
}, unvis.getDuration());
iv.setAlpha(1.0F);
iv.startAnimation(unvis);
} else {
iv.startAnimation(vis);
iv.setAlpha(1.0F);
}
}
});
}
https://github.com/square/picasso – Ufkoku