Android 从本地存储器加载图像时快速滚动

Android 从本地存储器加载图像时快速滚动,android,Android,从协调器布局和应用程序栏布局中的本地存储路径加载图像时,滚动时会出现抖动 我使用了myImageview.setImageURI(MYURI)但工作不正常我的问题解决了,因为我在使用毕加索,我曾尝试使用贝娄代码 Picasso.with(context).load(YOUR_IMAGE_URI).placeholder(R.drawable.profile_img).error(R.drawable.profile_imgd).resize(250,250).centerCrop().into

从协调器布局和应用程序栏布局中的本地存储路径加载图像时,滚动时会出现抖动


我使用了
myImageview.setImageURI(MYURI)但工作不正常

我的问题解决了,因为我在使用毕加索,我曾尝试使用贝娄代码

 Picasso.with(context).load(YOUR_IMAGE_URI).placeholder(R.drawable.profile_img).error(R.drawable.profile_imgd).resize(250,250).centerCrop().into(myImageview);
然而,我尝试了下面的代码,但我认为它可能会有所帮助

public static Bitmap decodeFile(File f, int reqWidth, int reqHeight) {
    Bitmap b = null;

    //Decode image size
    BitmapFactory.Options o = new BitmapFactory.Options();
    o.inJustDecodeBounds = true;

    FileInputStream fis = null;
    try {
        fis = new FileInputStream(f);
        BitmapFactory.decodeStream(fis, null, o);
        fis.close();

    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }

    //Decode with inSampleSize
    BitmapFactory.Options o2 = new BitmapFactory.Options();
    o2.inSampleSize = calculateInSampleSize(o2,reqWidth, reqHeight);

    try {
        fis = new FileInputStream(f);
        b = BitmapFactory.decodeStream(fis, null, o2);
        fis.close();
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    return b;

}

public static int calculateInSampleSize(
        BitmapFactory.Options options, int reqWidth, int reqHeight) {
    // Raw height and width of image
    final int height = options.outHeight;
    final int width = options.outWidth;
    int inSampleSize = 1;

    if (height > reqHeight || width > reqWidth) {

        final int halfHeight = height / 2;
        final int halfWidth = width / 2;

        // Calculate the largest inSampleSize value that is a power of 2 and keeps both
        // height and width larger than the requested height and width.
        while ((halfHeight / inSampleSize) > reqHeight
                && (halfWidth / inSampleSize) > reqWidth) {
            inSampleSize *= 2;
        }
    }

    return inSampleSize;
}

如果是相当重的,这并不奇怪,因为你在UI线程加载它。您可以尝试使用一些库,例如毕加索来加载它。当我使用库时,我使用了毕加索库,但当我不使用任何库时,我该怎么办?在后台线程中将图像加载到位图,然后将位图设置为ImageView这就是我的问题所在。问题是当我折叠我的工具栏时,它被卡住了