final Handler downloadHandler = new Handler() {
public void handleMessage(Message msg) {
Log.d("Yoon", "Handler");
MCImageDisposableView iconView = new MCImageDisposableView(profileSprite, tag);
iconView.setScale(0.5f);
iconView.setPosition(17, 145);
addActor(iconView);
}
};
Thread sb = new Thread(new Runnable() {
@Override
public void run() {
Log.d("Yoon", "Thread");
profileSprite = BitmapDownloader.downloadSprite(Utils.getImageURL(MyChoiceApp.shared.context, aid));
downloadHandler.sendEmptyMessage(0);
}
});
sb.start();
如果使用没有处理程序的线程,则更改actor(MCImageDisposableView具有sprite)图像。
但图像不正确。图片未加载我的网址。图像加载纹理图集
MCImageDisposableView类有donwload图像功能。它工作得很好......如果不使用线程。
如何加载异步图像?
答案 0 :(得分:1)
您需要为此实现延迟加载。
阅读下面提到的延迟加载链接:
Lazy load of images in ListView
这是执行此操作的基本思路:
addActor(){
//if you need to download image from url
downloadImageFromUrl(actorImageView, url);
}
downloadIamgeFromUrl(ImageView actorImageView, String url){
//ToDo : create Thread to download image from server
//ToDo : Once done, set this image to actorImageView in UI thread as
//runOnUiThread(new Runnable() {
@Override
public void run() {
actorImageView .setImageBitmap(bitmap);
}
});
}
答案 1 :(得分:1)
我为此创建了MyLazyImageList
。它基于ScrollPane
。现在看起来如下:
如果需要,您可以修改代码。所以源代码在这里: http://pastebin.com/JPWTB9PF或此处:http://pastebin.com/hi0v0nQy