【问题标题】:Slow loading ImageView in ListView - Android在 ListView 中缓慢加载 ImageView - Android
【发布时间】:2017-01-16 02:55:13
【问题描述】:

我已经阅读了一些关于在 Android 中加载图像的帖子,但这个论点对我来说有点令人困惑。 我有一个 ListView,我会在其中加载一些来自 firebase 存储的图像。我还有来自https://books.google 的其他图片,这些图片会立即加载。

当我从 Firebase 存储加载图像时,设备速度非常慢。我尝试过使用 Picasso 库以及以下代码:

 public class loadImage extends AsyncTask<String, String, Bitmap> {

    HttpURLConnection connection;
    BufferedReader reader;

    @Override
    protected Bitmap doInBackground(String... params) {
        try {
            URL url = new URL(params[0]);
            connection = (HttpURLConnection) url.openConnection();
            connection.connect();

            InputStream inputStream = connection.getInputStream();
            reader = new BufferedReader(new InputStreamReader(inputStream));
            StringBuilder stringBuffer = new StringBuilder();

            String line = "";
            while ((line = reader.readLine()) != null) {
                stringBuffer.append(line);
            }


            return BitmapFactory.decodeStream((InputStream) url.getContent());

        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (connection != null) {
                connection.disconnect();
            }
            try {
                if(reader != null) {
                    reader.close();
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return null;
    }

    @Override
    protected void onPostExecute(Bitmap result) {
        super.onPostExecute(result);
        bookImage.setImageBitmap(result);
    }
}

也许 Volley 比 Picasso 更好?还是 Fresco 或 Glide? 谁能帮帮我?

【问题讨论】:

  • 嘿,使用 github.com/thest1/LazyList。该库在后台下载您的列表视图图像,而不会影响列表视图滚动。
  • 只要在 google 上搜索 "ImageLoader" 你会发现很多解决方案
  • 我找到了解决方案:GLIDE。它比毕加索好,被谷歌推荐。感谢您的帮助
  • @Carlo 您可以发布并接受您自己的答案,以便正确标记此问题。 :)
  • 感谢@AL。我会做的

标签: android listview imageview picasso firebase-storage


【解决方案1】:

我找到了解决方案:GLIDE。它比 Picasso 好,是 Google 推荐的。 通过此链接,您可以了解 Glide 和 Picasso 的区别:

Glide vs Picasso

干得好。

【讨论】:

    猜你喜欢
    • 2012-08-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-09-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多