为1.5开发的java应用程序未在2.2 安卓上运行
我从在线教程中获得了查看大图像的代码。 它在1.5中运行良好,但是当我使用Android2.2库时,它不起作用。(我的应用程序使用2.2) 我一直在寻找这个问题的答案,但运气不好。我怀疑这可能与drawable文件夹有关? 图像加载,但无法执行缩放或移动图像等操作
private void updateDisplay(){
calculateSourceRect(current_centerX, current_centerY, current_scale);
//where sourceRect = new RectF(); and destinationRect = new RectF();
matrix.setRectToRect(sourceRect, destinationRect, Matrix.ScaleToFit.FILL);
安卓BigImageView.setImageMatrix(matrix);
}
private void calculateSourceRect(int centerX, int centerY, float scale){
int xSubValue;
int ySubValue;
if(destinationRect.bottom >= destinationRect.right){
ySubValue = (int)((imageSizeY/2) / scale);
xSubValue = ySubValue;
xSubValue = (int) (xSubValue * ((float)安卓BigImageView.getWidth() / (float)安卓BigImageView.getHeight()));
}
else{
xSubValue = (int)((imageSizeX/2) / scale);
ySubValue = xSubValue;
ySubValue = (int) (ySubValue * ((float)安卓BigImageView.getHeight() / (float)安卓BigImageView.getWidth()));
}
if(centerX - xSubValue < 0) {
animation.stopProcess();
centerX = xSubValue;
}
if(centerY - ySubValue < 0) {
animation.stopProcess();
centerY = ySubValue;
}
if(centerX + xSubValue >= imageSizeX) {
animation.stopProcess();
centerX = imageSizeX - xSubValue - 1;
}
if(centerY + ySubValue >= imageSizeY) {
animation.stopProcess();
centerY = imageSizeY - ySubValue - 1;
}
current_centerX = centerX;
current_centerY = centerY;
sourceRect.set(centerX - xSubValue, centerY - ySubValue, centerX + xSubValue, centerY + ySubValue);
}
# 1 楼答案
试试
androidBigImageView.setScaleType(ScaleType.MATRIX);