Android while using cardview image is loading very lazy

冷暖自知 提交于 2019-12-03 21:57:10

Try scale your bitmap to lower its actual resolution, I've used the following codes to reduce bitmap's size.

int nh = (int) (bitmap.getHeight() * (512.0 / bitmap.getWidth()));
Bitmap scaled = Bitmap.createScaledBitmap(bitmap, 512, nh, true);

For you case, add the following codes into your adapter class AsyncTask's doInBackground method

try {
     bitmap = BitmapFactory.decodeStream((InputStream) new URL(args[0]).getContent());
     int nh = (int) (bitmap.getHeight() * (512.0 / bitmap.getWidth()));
     Bitmap scaled = Bitmap.createScaledBitmap(bitmap, 512, nh, true);
    } catch (Exception e) {
        e.printStackTrace();
        }
     return scaled;

Return scaled bitmap instead of original bitmap.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!