code: private void checkBorderAndCenterWhenScale() {
  
  		RectF rect = getMatrixRectF();
  		float deltaX = 0;
  		float deltaY = 0;
  
  		int width = getWidth();
  		int height = getHeight();
  
  		if (rect.width() >= width) {
  			if (rect.left > 0) {
  				deltaX = -rect.left;
  			}
  			if (rect.right < width) {
  				deltaX = width - rect.right;
  			}
  		}
  		if (rect.height() >= height) {
  			if (rect.top > 0) {
  				deltaY = -rect.top;
  			}
  			if (rect.bottom < height) {
  				deltaY = height - rect.bottom;
  			}
  		}
  		// Always center the image when it's smaller than the imageView
  		if (rect.width() < width) {
  			deltaX = width * 0.5f - rect.right + 0.5f * rect.width();
  		}
  		if (rect.height() < height) {
  			deltaY = height * 0.5f - rect.bottom + 0.5f * rect.height();
  		}
  
  		scaleMatrix.postTranslate(deltaX, deltaY);
  
  	}
docs: Prevent visual artifact when scaling