2
上運行我已經從聯機教程中查看大圖片的代碼。 它工作正常1.5,但是當我使用Android 2.2庫它不起作用。 (我的應用程序使用2.2) 我已經搜索了這個問題的答案,但沒有運氣。我懷疑它可以與可繪製的文件夾有關嗎? 圖像加載,但無法完成縮放或移動圖像等操作。針對1.5開發的應用程序未在2.2 android
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);
}
嘗試'androidBigImageView.setScaleType(ScaleType.MATRIX);' – Aidanc 2011-03-26 00:55:34
謝謝Aidanc!像魅力一樣工作! – Alanagh 2011-03-26 00:58:57
沒問題!我做了一個答案;) – Aidanc 2011-03-26 01:37:06