1

I am using PhotoView Picasso on my Android application. I want to toggle two images by clicking a button, keeping the zoom and the xy coordinates. I can keep the zoom, but it is hard to keep the xy coordinates because two images have different resolutions and I have to keep the relative xy coordinates AFTER the zoom. When I toggle to a new image, if I don't keep the xy coordinates, the zoomed image is always at the center. Below is my current code, which only implements keeping the zoom.

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {

    // ... some basic stuffs here

    mRequestCreator1 = Picasso.get().load(mImageUri1);
    mRequestCreator2 = Picasso.get().load(mImageUri2);
    mRequestCreator1.into(mPhotoView);

    mBtnSwitch.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            final float prevScale = mPhotoView.getScale();
            // MUST use the callback because of timing issue.
            Callback callback = new Callback() {
                @Override
                public void onSuccess() { mPhotoView.setScale(prevScale); }

                @Override
                public void onError(Exception e) { e.printStackTrace(); }
            };

            if(sPrevIsOriginal) {
                mRequestCreator2.into(mPhotoView, callback);
            } else {
                mRequestCreator1.into(mPhotoView, callback);
            }
            sPrevIsOriginal = !sPrevIsOriginal;
        }
    });
}
4

1 回答 1

1

经过大量的试验和错误,我发现了如何做到这一点。您必须使用 获取前一张图像的补充矩阵getSuppMatrix(),然后使用 将该补充矩阵应用于新图像setSuppMatrix()。使用补充矩阵很重要。永远不要试图通过操作getImageMatrix()or来做到这一点getDisplayMatrix(),因为它要么不起作用,要么代码会变得更加复杂。

于 2018-06-14T01:55:01.693 回答