1

我正在开发一个使用多个图像的 Android 应用程序,我想在网络服务器上传输更大的图像(2-6 MB)以在需要时下载它们。
我以前从未尝试过,所以我找到了一种使用 AsyncTask 在按钮单击时下载图像的方法,这是最好的解决方案吗?

有更好的选择或意见吗?


编辑:我正在尝试 koush 的 ion

编辑 2:我尝试了 ion ( https://github.com/koush/ion ),我非常喜欢这里,非常易于使用。建议

4

5 回答 5

2
   Use Universal image loader for downloading images asynchronously.  

  [https://github.com/nostra13/Android-Universal-Image-Loader][1].


  The Library itself has a sample code to download image.you may refer it..


  [1]: https://github.com/nostra13/Android-Universal-Image-Loader
After downloading library  add library with your project and insert the below code at necessary place


String final_url="www.google.com/.....";
ImageView image;

ImageLoader  imageloader = ImageLoader.getInstance();

imageloader.init(ImageLoaderConfiguration.createDefault(context));

DisplayImageOptions options; = new DisplayImageOptions.Builder()
                .showImageForEmptyUri(R.drawable.ic_empty)
                .showImageOnFail(R.drawable.ic_error)
                .resetViewBeforeLoading(true).cacheOnDisk(true)
                .imageScaleType(ImageScaleType.EXACTLY)
                .bitmapConfig(Bitmap.Config.RGB_565).considerExifParams(true)
                .cacheInMemory(true)
                .displayer(new FadeInBitmapDisplayer(300)).build();
imageloader.displayImage(final_url, image);
于 2014-08-26T09:05:28.957 回答
2

I strongly recommend to use Glide or Picasso, which are the most used libraries nowadays. Just google "Glide for Android" or "Picasso for Android" and they take care of the threading, caching, optimization, etc. I hope it helps!

于 2016-03-25T13:38:35.070 回答
1

最佳实践:http: //developer.android.com/training/displaying-bitmaps/index.html。有用的库:Picasso - http://square.github.io/picasso;滑翔 - github.com/bumptech/glide。

于 2014-08-26T07:47:59.107 回答
0

为此使用延迟加载图像并使用图像缓存。这是最好的方法。

https://github.com/thest1/LazyList

http://androidexample.com/Download_Images_From_Web_And_Lazy_Load_In_ListView_-_Android_Example/index.php?view=article_discription&aid=112&aaid=134

http://sunil-android.blogspot.in/2013/09/lazy-loading-image-download-from.html

您可以找到更多延迟加载的示例。希望上面的链接也有用。

于 2014-08-26T07:30:40.630 回答
0

实际上,使用的最重要原因AsyncTask是您想要一种机制来执行冗长的操作而不会阻塞您的 UI。有了它,您还可以摆脱管理子线程和同步。就是这样。如果您想要其他功能,例如位图缓存,则必须自己实现或使用一些第三方工具。

于 2014-08-26T07:07:49.467 回答