在没有中心对齐的情况下保持照片视图的缩放
Retain zoom in photoview without centre aligining
我有一个要求稍作修改。 保留方向更改的缩放并使其居中。我不希望图像居中对齐。我只想保持缩放。如何实现?任何帮助将不胜感激。
经过如此多的头脑风暴,我达到了预期的行为。思路是先保存图像之前的矩阵和缩放比例,然后将之前存储的矩阵填充到图像上。
获取以前的值:
Matrix previousImageMatrix = photoView.getDisplayMatrix();
previousImageMatrix.getValues(previousValues);
previousZoomLevel = prescription.getScale();
现在附上 photoView.getViewTreeObserver().addOnPreDrawListener(this);
图像缩放时填充上面的矩阵 onPreDraw()
方法如下:
@Override
public boolean onPreDraw()
{
photoView.getViewTreeObserver().removeOnPreDrawListener(this);
Matrix theMatrix = photoView.getDisplayMatrix();
Log.d("***", "onPreDraw: TransX = " + previousValues[2] + "TransY = " + previousValues[5]);
float[] matrixValues = new float[9];
matrixValues[0] = previousZoomLevel; // 0 and 4 store the scaleX and scaleY
matrixValues[4] = previousZoomLevel;
if (previousZoomLevel == MIN_ZOOM_LEVEL) // Zoom Level starts from 1.0 to 16.0
{
matrixValues[2] = 0; //2 and 5 store store TransX and TransY
matrixValues[5] = 0;
} else
{
matrixValues[2] = previousValues[2];
matrixValues[5] = previousValues[5];
}
Log.d("***", "onPreDraw: NEW.. TransX = " + matrixValues[2] + "TransY = " + matrixValues[5]);
matrixValues[8] = 1.0f;
theMatrix.setValues(matrixValues);
prescription.setDisplayMatrix(theMatrix);
Matrix theImageViewMatrix = photoView.getDisplayMatrix();
prescription.setImageMatrix(theImageViewMatrix);
return true;
}
希望这对某人有所帮助。
我有一个要求稍作修改。
经过如此多的头脑风暴,我达到了预期的行为。思路是先保存图像之前的矩阵和缩放比例,然后将之前存储的矩阵填充到图像上。 获取以前的值:
Matrix previousImageMatrix = photoView.getDisplayMatrix();
previousImageMatrix.getValues(previousValues);
previousZoomLevel = prescription.getScale();
现在附上 photoView.getViewTreeObserver().addOnPreDrawListener(this);
图像缩放时填充上面的矩阵 onPreDraw()
方法如下:
@Override
public boolean onPreDraw()
{
photoView.getViewTreeObserver().removeOnPreDrawListener(this);
Matrix theMatrix = photoView.getDisplayMatrix();
Log.d("***", "onPreDraw: TransX = " + previousValues[2] + "TransY = " + previousValues[5]);
float[] matrixValues = new float[9];
matrixValues[0] = previousZoomLevel; // 0 and 4 store the scaleX and scaleY
matrixValues[4] = previousZoomLevel;
if (previousZoomLevel == MIN_ZOOM_LEVEL) // Zoom Level starts from 1.0 to 16.0
{
matrixValues[2] = 0; //2 and 5 store store TransX and TransY
matrixValues[5] = 0;
} else
{
matrixValues[2] = previousValues[2];
matrixValues[5] = previousValues[5];
}
Log.d("***", "onPreDraw: NEW.. TransX = " + matrixValues[2] + "TransY = " + matrixValues[5]);
matrixValues[8] = 1.0f;
theMatrix.setValues(matrixValues);
prescription.setDisplayMatrix(theMatrix);
Matrix theImageViewMatrix = photoView.getDisplayMatrix();
prescription.setImageMatrix(theImageViewMatrix);
return true;
}
希望这对某人有所帮助。