2015-10-27 3 views
0

Я внедрил рабочий RecyclerView с всплывающим окном анимации. Код, который я использовал для масштабирования вида (изображения) в RecyclerView, был взят отсюда: https://developer.android.com/training/animation/zoom.htmlAndroid RecyclerView с ViewPager

После того, как анимация изображения закончилась, я хочу, чтобы она могла перемещаться влево и вправо на другие изображения. Есть ли хороший способ сделать это?

Мой код для изменения масштаба изображения (Сразу после уменьшенное изображение полностью увеличено, отображается тем лучше разрешение изображения):

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 и отображать более высокое разрешение изображения после завершения анимации, он не проходит гладко.

ответ

0

Решение состоит в том, чтобы масштабировать ViewPager вместо масштабирования изображения. Это прекрасно работает.

Смежные вопросы