我对通用图像加载器有另一个问题。尝试在列表视图和网格视图中使用它来显示大量图像。传递给 UIL 的 url 包含高分辨率图像。我已经尝试使用几乎所有的 scaletypes,它在移动网络上加载图像的速度仍然比 Original LazyList 慢得多。据我了解,它首先加载确切的图像,然后调整它的大小。有没有办法下载更少量的数据来显示这个非常缩放的图像。此外,它有时会在加载图像时出现两个不同的异常。EOFException 和 SocketTimeoutException。有什么想法我在这里做错了吗?
更新: 适配器类:
public class LazyAdapter extends BaseAdapter {
private Activity activity;
private List<String[]> data;
private static LayoutInflater inflater=null;
public ImageLoade1r imageLoader;
public boolean show;
public final String webs = "http://www";
public DisplayImageOptions options;
public ImageLoader nostra;
public LazyAdapter(Activity a, List<String[]> d, boolean flag) {
activity = a;
data=d;
show=flag;
ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(a.getApplicationContext())
.enableLogging()
.build();
nostra = ImageLoader.getInstance();
nostra.init(config);
options = new DisplayImageOptions.Builder()
.cacheOnDisc()
.showImageOnFail(R.drawable.failed)
.imageScaleType(ImageScaleType.EXACTLY)
.bitmapConfig(Bitmap.Config.RGB_565)
.build();
inflater = (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
imageLoader=new ImageLoade1r(activity.getApplicationContext());
}
public int getCount() {
return data.size();
}
public Object getItem(int position) {
return position;
}
public long getItemId(int position) {
return position;
}
public View getView(int position, View convertView, ViewGroup parent) {
View vi=convertView;
String[] url = data.get(position);
if(convertView==null)
vi = inflater.inflate(R.layout.item, null);
TextView text=(TextView)vi.findViewById(R.id.text);;
ImageView image=(ImageView)vi.findViewById(R.id.image);
ProgressBar spinner = (ProgressBar) vi.findViewById(R.id.prgrsItem);
RelativeLayout layo = (RelativeLayout) vi.findViewById(R.id.thelayout);
if(url[1].trim().equals("folder"))
{
String img = webs+url[3].trim() + url[2] +"title"+".jpg";
display(image, img, spinner);
text.setText(url[2].replaceAll("_", " "));
}
else
{
String img;
if(show==true)
img = webs+url[3] + url[2]+"title"+".jpg";
else
img = webs+url[0];
display(image, img, spinner);
text.setText(url[2].replaceAll("_", " "));
}
if(show==true)
{
text.setVisibility(View.VISIBLE);
}
else
{
text.setVisibility(View.GONE);
}
return vi;
}
public void display(ImageView img, String url, final ProgressBar spinner)
{
nostra.displayImage(url, img, options, new ImageLoadingListener() {
@Override
public void onLoadingStarted(String imageUri, View view) {
spinner.setVisibility(View.VISIBLE);
}
@Override
public void onLoadingFailed(String imageUri, View view, FailReason failReason) {
spinner.setVisibility(View.GONE);
EasyTracker.getTracker().sendException(failReason.toString(), false);
}
@Override
public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
spinner.setVisibility(View.GONE);
}
@Override
public void onLoadingCancelled(String imageUri, View view) {
}
});
}
}
更新EOFException:
03-21 13:51:55.800: E/ImageLoader(31605): null
03-21 13:51:55.800: E/ImageLoader(31605): java.io.EOFException
03-21 13:51:55.800: E/ImageLoader(31605): at libcore.io.Streams.readAsciiLine(Streams.java:203)
03-21 13:51:55.800: E/ImageLoader(31605): at libcore.net.http.HttpEngine.readResponseHeaders(HttpEngine.java:544)
03-21 13:51:55.800: E/ImageLoader(31605): at libcore.net.http.HttpEngine.readResponse(HttpEngine.java:784)
03-21 13:51:55.800: E/ImageLoader(31605): at libcore.net.http.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:274)
03-21 13:51:55.800: E/ImageLoader(31605): at libcore.net.http.HttpURLConnectionImpl.getResponseCode(HttpURLConnectionImpl.java:479)
03-21 13:51:55.800: E/ImageLoader(31605): at com.nostra13.universalimageloader.core.download.BaseImageDownloader.getStreamFromNetwork(BaseImageDownloader.java:113)
03-21 13:51:55.800: E/ImageLoader(31605): at com.nostra13.universalimageloader.core.download.BaseImageDownloader.getStream(BaseImageDownloader.java:84)
03-21 13:51:55.800: E/ImageLoader(31605): at com.nostra13.universalimageloader.core.LoadAndDisplayImageTask.saveImageOnDisc(LoadAndDisplayImageTask.java:299)
03-21 13:51:55.800: E/ImageLoader(31605): at com.nostra13.universalimageloader.core.LoadAndDisplayImageTask.tryLoadBitmap(LoadAndDisplayImageTask.java:237)
03-21 13:51:55.800: E/ImageLoader(31605): at com.nostra13.universalimageloader.core.LoadAndDisplayImageTask.run(LoadAndDisplayImageTask.java:149)
03-21 13:51:55.800: E/ImageLoader(31605): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
03-21 13:51:55.800: E/ImageLoader(31605): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
03-21 13:51:55.800: E/ImageLoader(31605): at java.lang.Thread.run(Thread.java:856)