PhotoViewAttacher清除imageView边界和缩放级别

Vea*_*rji 11 android zoom imageview

我正在使用PhotoView库来实现缩放Android ImageView.缩放工作正常.

我正在使用low-qualityin 设置图像,ImageView然后开始下载hight-quality将替换low-quality图像的新图像.

如果用户放大low-quality图像 - high-quality图像将替换现有图像并缩小缩放级别:(

如何在加载high-quality图像后保存缩放级别?

我一直试图让图像MatrixPhotoViewAttacherlow-quality和它设置为high-quality image,但它不工作-图像缩放级别和范围是不一样的,因为他们之前.该high-quality图像取代了low-quality图像ImageView.

    Matrix matrix;
    imageView.setImageBitmap(imageBitmap);
    ...

    PhotoViewAttacher  mAttacher = new PhotoViewAttacher(imageView);
    // save the matrix before any modifications
    matrix = mAttacher.getDisplayMatrix(); 
    mAttacher.setOnMatrixChangeListener(new OnMatrixChangedListener() {
        @Override
        public void onMatrixChanged(RectF rect) {
            // update the matrix
            matrix = mAttacher.getDisplayMatrix(); 
        }
    });

    imageProvider.load(getActivity(), imageView, imageUrl, progressBarView, imageConfig, new ImageCallback() {
        @Override
        public void onSuccess(ImageView imageView) {
            // update image in ImageView
            // probably the problem is in this .update() call
            // but I don't get what's the exact problem
            mAttacher.update();
            // restore high-quality image matrix
            mAttacher.setDisplayMatrix(matrix);
        }

        @Override
        public void onError(ImageView imageView) {

        }
    });
Run Code Online (Sandbox Code Playgroud)

编辑:图像具有不同的尺寸.

woo*_*oot 0

查看PhotoViewAttacher.java的代码后- 调用似乎update()做了两件事:

  1. 确保 的比例类型ImageView设置为ScaleType.MATRIX
  2. 使当前矩阵无效并根据新的维度重新计算Drawable

因此,假设您的第一张图像和第二张图像具有完全相同的尺寸,您可以跳过调用update(),这应该保留当前的缩放和平移值。