コード例 #1
0
  @Override
  public Object instantiateItem(ViewGroup container, int position) {

    View itemView = mLayoutInflater.inflate(R.layout.item_preview, container, false);

    PhotoView imageView = (PhotoView) itemView.findViewById(R.id.iv_pager);

    final String path = paths.get(position);
    final Uri uri;
    if (path.startsWith("http")) {
      uri = Uri.parse(path);
    } else {
      uri = Uri.fromFile(new File(path));
    }
    Glide.with(mContext)
        .load(uri)
        //            .placeholder(R.mipmap.default_error)
        .error(R.mipmap.default_error)
        .crossFade()
        .into(imageView);

    imageView.setOnPhotoTapListener(
        new PhotoViewAttacher.OnPhotoTapListener() {
          @Override
          public void onPhotoTap(View view, float v, float v1) {
            if (listener != null) {
              listener.OnPhotoTapListener(view, v, v1);
            }
          }
        });

    container.addView(itemView);

    return itemView;
  }
コード例 #2
0
    /** 用来实例化页卡 */
    @Override
    public Object instantiateItem(ViewGroup container, int position) {
      PhotoView photoView = new PhotoView(mContext);
      //            photoView.setScaleType(ImageView.ScaleType.CENTER);
      photoView.setScaleType(ImageView.ScaleType.FIT_CENTER);
      Glide.with(mContext).load(mPictures.get(position)).into(photoView);
      // Now just add PhotoView to ViewPager and return it
      container.addView(
          photoView, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
      // 单击图片
      photoView.setOnPhotoTapListener(
          new PhotoViewAttacher.OnPhotoTapListener() {
            @Override
            public void onPhotoTap(View view, float v, float v1) {
              mOnSingleClickListener.singleClickFinish();
            }

            @Override
            public void onOutsidePhotoTap() {
              mOnSingleClickListener.singleClickFinish();
            }
          });
      return photoView;
    }
コード例 #3
0
    @Override
    public View instantiateItem(ViewGroup container, final int position) {
      final PhotoView photoView = new PhotoView(container.getContext());
      photoView.setImageResource(sDrawables[position]);

      // Now just add PhotoView to ViewPager and return it
      container.addView(photoView, LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
      photoView.setOnPhotoTapListener(
          new PhotoViewAttacher.OnPhotoTapListener() {
            public void onPhotoTap(
                View paramAnonymousView, float paramAnonymousFloat1, float paramAnonymousFloat2) {
              if (mCurrentAnimator != null) {
                mCurrentAnimator.cancel();
              }

              photoView.clearZoom();

              boolean scaleResult = getScaleFinalBounds(position);
              // Animate the four positioning/sizing properties in parallel,
              // back to their
              // original values.
              AnimatorSet as = new AnimatorSet();
              ObjectAnimator containAlphaAnimator =
                  ObjectAnimator.ofFloat(((MainActivity) mContext).gridView, "alpha", 0.f, 1.0f);
              if (scaleResult) {
                ObjectAnimator animatorX = ObjectAnimator.ofFloat(viewPager, "x", startBounds.left);
                ObjectAnimator animatorY = ObjectAnimator.ofFloat(viewPager, "y", startBounds.top);
                ObjectAnimator animatorScaleX =
                    ObjectAnimator.ofFloat(viewPager, "scaleX", startScaleFinal);
                ObjectAnimator animatorScaleY =
                    ObjectAnimator.ofFloat(viewPager, "scaleY", startScaleFinal);

                as.play(containAlphaAnimator)
                    .with(animatorX)
                    .with(animatorY)
                    .with(animatorScaleX)
                    .with(animatorScaleY);
              } else {
                // the selected photoview is beyond the mobile screen display
                // so it just fade out
                ObjectAnimator alphaAnimator = ObjectAnimator.ofFloat(viewPager, "alpha", 0.1f);
                as.play(alphaAnimator).with(containAlphaAnimator);
              }
              as.setDuration(mShortAnimationDuration);
              as.setInterpolator(new DecelerateInterpolator());
              as.addListener(
                  new AnimatorListenerAdapter() {

                    @Override
                    public void onAnimationEnd(Animator animation) {
                      viewPager.clearAnimation();
                      viewPager.setVisibility(View.GONE);
                      mCurrentAnimator = null;
                    }

                    @Override
                    public void onAnimationCancel(Animator animation) {
                      viewPager.clearAnimation();
                      viewPager.setVisibility(View.GONE);
                      mCurrentAnimator = null;
                    }
                  });
              as.start();
              mCurrentAnimator = as;
            }
          });

      return photoView;
    }