code: private void checkMatrixBounds() {
  		RectF rect = getMatrixRectF();
  
  		float deltaX = 0, deltaY = 0;
  		final float viewWidth = getWidth();
  		final float viewHeight = getHeight();
  		// Check if image boundary exceeds imageView boundary
  		if (rect.top > 0 && isCheckTopAndBottom) {
  			deltaY = -rect.top;
  		}
  		if (rect.bottom < viewHeight && isCheckTopAndBottom) {
  			deltaY = viewHeight - rect.bottom;
  		}
  		if (rect.left > 0 && isCheckLeftAndRight) {
  			deltaX = -rect.left;
  		}
  		if (rect.right < viewWidth && isCheckLeftAndRight) {
  			deltaX = viewWidth - rect.right;
  		}
  		scaleMatrix.postTranslate(deltaX, deltaY);
  	}
docs: Check image bounday against imageView