为1.5开发的应用程序不在2.2 android上运行

时间:2011-03-26 00:49:48

标签: java android

我已经获得了从在线教程中查看大图像的代码。 它适用于1.5,但是当我使用Android 2.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);
    androidBigImageView.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)androidBigImageView.getWidth() / (float)androidBigImageView.getHeight()));
    }
    else{
        xSubValue = (int)((imageSizeX/2) / scale);
        ySubValue = xSubValue;

        ySubValue = (int) (ySubValue * ((float)androidBigImageView.getHeight() / (float)androidBigImageView.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 个答案:

答案 0 :(得分:1)

尝试androidBigImageView.setScaleType(ScaleType.MATRIX);