Android RecyclerView 与 ViewPager

Android RecyclerView with ViewPager

我已经实现了一个带有图像动画弹出窗口的有效 RecyclerView。我在 RecyclerView 中用于缩放视图(图像)的代码取自此处:https://developer.android.com/training/animation/zoom.html

图片动画结束后,我想可以左右滑动到其他图片。有什么好的方法吗?

我的缩放图像代码(缩略图完全缩放后,显示图像的更好分辨率):

public void zoomImageFromThumb(final View thumbView, final Bitmap path,final String image) {
    if (mCurrentAnimator != null) {
        mCurrentAnimator.cancel();
    }

    final TouchImageView  imageView  = (TouchImageView) activity.findViewById(R.id.expanded_image);

    imageView.setImageBitmap(path);//thumbnail image

    final Rect startBounds = new Rect();
    final Rect finalBounds = new Rect();
    final Point globalOffset = new Point();

    thumbView.getGlobalVisibleRect(startBounds);
    this.activity.findViewById(R.id.container).getGlobalVisibleRect(finalBounds, globalOffset);
    startBounds.offset(-globalOffset.x, -globalOffset.y);
    finalBounds.offset(-globalOffset.x, -globalOffset.y);

    float startScale;
    if ((float) finalBounds.width() / finalBounds.height() > (float) startBounds.width() / startBounds.height()) {
        startScale = (float) startBounds.height() / finalBounds.height();
        float startWidth = startScale * finalBounds.width();
        float deltaWidth = (startWidth - startBounds.width()) / 2;
        startBounds.left -= deltaWidth;
        startBounds.right += deltaWidth;
    } else {
        startScale = (float) startBounds.width() / finalBounds.width();
        float startHeight = startScale * finalBounds.height();
        float deltaHeight = (startHeight - startBounds.height()) / 2;
        startBounds.top -= deltaHeight;
        startBounds.bottom += deltaHeight;
    }

    thumbView.setAlpha(0f);
    imageView.setVisibility(View.VISIBLE);

    imageView.setPivotX(0f);
    imageView.setPivotY(0f);

    AnimatorSet set = new AnimatorSet();
    set.play(ObjectAnimator.ofFloat(imageView, View.X, startBounds.left, finalBounds.left)).with(ObjectAnimator.ofFloat(imageView, View.Y, startBounds.top,
            finalBounds.top))
            .with(ObjectAnimator.ofFloat(imageView, View.SCALE_X, startScale, 1f))
            .with(ObjectAnimator.ofFloat(imageView, View.SCALE_Y, startScale, 1f));

    set.setDuration(mShortAnimationDuration);
    set.setInterpolator(new DecelerateInterpolator());
    set.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {
            mCurrentAnimator = null;
            imageView.setImageURI(Uri.parse(image));//Better resolution of an image is displayed
        }
        @Override
        public void onAnimationCancel(Animator animation) {
            mCurrentAnimator = null;
        }
    });

如果我只是转到 ViewPager 并在动画完成后显示更高分辨率的图像,则不会很顺利。

解决方案是缩放 ViewPager 而不是缩放图像。它以这种方式完美运行。