com.gloomyer.zoomimageview.ZoomImageView类的使用及代码示例

x33g5p2x  于2022-02-05 转载在 其他  
字(5.3k)|赞(0)|评价(0)|浏览(75)

本文整理了Java中com.gloomyer.zoomimageview.ZoomImageView类的一些代码示例,展示了ZoomImageView类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ZoomImageView类的具体详情如下:
包路径:com.gloomyer.zoomimageview.ZoomImageView
类名称:ZoomImageView

ZoomImageView介绍

[英]可根据点击/多指触控 放大,放小的ImageVIew
[中]可根据点击/多指触控 放大,放小的ImageVIew

代码示例

代码示例来源:origin: Gloomyer/ZoomImageView

@Override
public void setImageResource(int resId) {
  reSetState();
  super.setImageResource(resId);
}

代码示例来源:origin: Gloomyer/ZoomImageView

/**
 * 在移动图片的时候进行边界检查
 */
private void checkBorderWhenTranslate() {
  RectF rectF = getMatrixRectF();
  float deltaX = 0;
  float deltaY = 0;
  int width = getWidth();
  int height = getHeight();
  if (rectF.top > 0 && isCheckTopAndBottom) {
    deltaY = -rectF.top;
  }
  if (rectF.bottom < height && isCheckTopAndBottom) {
    deltaY = height - rectF.bottom;
  }
  if (rectF.left > 0 && isCheckLeftAndRight) {
    deltaX = -rectF.left;
  }
  if (rectF.right < width && isCheckLeftAndRight) {
    deltaX = width - rectF.right;
  }
  mMatrix.postTranslate(deltaX, deltaY);
  setImageMatrix(mMatrix);
}

代码示例来源:origin: Gloomyer/ZoomImageView

@Override
protected void onAttachedToWindow() {
  super.onAttachedToWindow();
  log("注册了OnGlobalLayoutListener");
  getViewTreeObserver().addOnGlobalLayoutListener(this);
}

代码示例来源:origin: Gloomyer/ZoomImageView

RectF rectF = getMatrixRectF();
if ((rectF.width() > getWidth() + 0.01f || (rectF.height() > getHeight() + 0.01f))) {
  if ((rectF.right != getWidth()) && (rectF.left != 0)) {
    try {
      getParent().requestDisallowInterceptTouchEvent(true);
    } catch (Exception e) {
      log(e.toString());
  isCanDrag = isMoveAction(dx, dy);
  RectF rectF = getMatrixRectF();
  if (getDrawable() != null) {
    isCheckLeftAndRight = isCheckTopAndBottom = true;
    if (rectF.width() <= getWidth()) {
      isCheckLeftAndRight = false;
      dx = 0;
    if (rectF.height() <= getHeight()) {
      isCheckTopAndBottom = false;
      dy = 0;
    checkBorderWhenTranslate();
    setImageMatrix(mMatrix);
RectF rect = getMatrixRectF();
if ((rect.width() > getWidth() + 0.01f || (rect.height() > getHeight() + 0.01f))) {
  if ((rect.right != getWidth()) && (rect.left != 0)) {

代码示例来源:origin: Gloomyer/ZoomImageView

return;
setScaleType(ScaleType.MATRIX);
log("执行了onGlobalLayout| NULL:" + (getDrawable() == null));
if (getDrawable() == null || getWidth() == 0 || getHeight() == 0) return;
  log("初始化完毕");
  int width = getWidth();
  int height = getHeight();
  float screenWeight = height * 1.0f / width;
  int imageH = getDrawable().getIntrinsicHeight(); // 图片高度
  int imageW = getDrawable().getIntrinsicWidth(); // 图片宽度
  float imageWeight = imageH * 1.0f / imageW;
      log("max scale:" + scale);
      log("min scale:" + scale);
    int dx = getWidth() / 2 - imageW / 2;
    int dy = getHeight() / 2 - imageH / 2;
  setImageMatrix(mMatrix);
  isInit = true;

代码示例来源:origin: Gloomyer/ZoomImageView

@Override
public Object instantiateItem(ViewGroup container, int position) {
  ZoomImageView ziv = new ZoomImageView(MultiImageAct.this);
  ViewGroup.LayoutParams layoutParams = new ViewGroup.LayoutParams(
      ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
  ziv.placeholder(R.mipmap.ic_launcher);
  ziv.reSetState();
  Glide.with(MultiImageAct.this)
      .load(imgs[position])
      .into(ziv);
  //ziv.setImageForUrl(imgs[position]);
  ziv.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
      MultiImageAct.this.finish();
    }
  });
  container.addView(ziv, layoutParams);
  return ziv;
}

代码示例来源:origin: Gloomyer/ZoomImageView

@Override
public boolean onScale(ScaleGestureDetector detector) {
  float scaleFactor = detector.getScaleFactor();//获取用户手势判断出来的缩放值
  float scale = getScale();
  /**
   * 没有图片
   */
  if (getDrawable() == null) return true;
  //缩放范围控制
  if ((scale < mMaxScale && scaleFactor > 1.0f) || (scale > mMinScale && scaleFactor < 1.0f)) {
    if (scaleFactor * scale < mMinScale) {
      scaleFactor = mMinScale / scale;
    }
    if (scale * scaleFactor > mMaxScale) {
      scaleFactor = mMaxScale / scale;
    }
    mMatrix.postScale(scaleFactor, scaleFactor, detector.getFocusX(), detector.getFocusY());
    checkBorderAndCenterWhenScale();
    setImageMatrix(mMatrix);
  }
  return true;
}

代码示例来源:origin: Gloomyer/ZoomImageView

/**
 * 获取图片放大缩小后的宽高/top/left/right/bottom
 *
 * @return
 */
private RectF getMatrixRectF() {
  RectF rectF = new RectF();
  Drawable drawable = getDrawable();
  if (drawable != null) {
    rectF.set(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight());
    mMatrix.mapRect(rectF);
  }
  return rectF;
}

代码示例来源:origin: Gloomyer/ZoomImageView

/**
 * 在缩放的时候进行边界,位置 检查
 */
private void checkBorderAndCenterWhenScale() {
  RectF rectF = getMatrixRectF();
  float deltaX = 0;
  float deltaY = 0;
  int width = getWidth();
  int height = getHeight();
  if (rectF.width() >= width) {
    if (rectF.left > 0)
      deltaX = -rectF.left;
    if (rectF.right < width)
      deltaX = width - rectF.right;
  }
  if (rectF.height() >= height) {
    if (rectF.top > 0)
      deltaY = 0;
    if (rectF.bottom < height)
      deltaY = height - rectF.bottom;
  }
  if (rectF.width() < width) {
    deltaX = width / 2f - rectF.right + rectF.width() / 2;
  }
  if (rectF.height() < height) {
    deltaY = height / 2f - rectF.bottom + rectF.height() / 2;
  }
  mMatrix.postTranslate(deltaX, deltaY);
  setImageMatrix(mMatrix);
}

代码示例来源:origin: Gloomyer/ZoomImageView

@Override
public void setImageBitmap(Bitmap bm) {
  reSetState();
  super.setImageBitmap(bm);
}

代码示例来源:origin: Gloomyer/ZoomImageView

@SuppressLint("NewApi")
@Override
@SuppressWarnings("deprecation")
protected void onDetachedFromWindow() {
  super.onDetachedFromWindow();
  log("反注册了OnGlobalLayoutListener");
  getViewTreeObserver().removeOnGlobalLayoutListener(this);
}

代码示例来源:origin: Gloomyer/ZoomImageView

@Override
public void setImageDrawable(Drawable drawable) {
  reSetState();
  super.setImageDrawable(drawable);
}

相关文章

ZoomImageView类方法