從您發佈的圖片我假設你對你的ImageView
這樣你就可以計算顯示大小,像這樣
boolean landscape = imageView.getWidth() > imageView.getHeight();
float displayedHeight;
float displayedWidth;
if (landscape){
displayedHeight = imageView.getHeight();
displayedWidth = (float) drawableWidth * imageView.getHeight()/drawableHeight;
} else {
displayedHeight = (float) drawableHeight * imageView.getWidth()/drawableWidth;
displayedWidth = imageView.getWidth();
}
注有FIT_CENTER的scaleType(或CENTER_INSIDE與繪製比ImageView的大):代碼爲了可讀性而不簡化。
可應用於所有scaleTypes另一種更魯棒的方法是使用其的ImageView用於縮放圖像
float[] f = new float[9];
imageView.getImageMatrix().getValues(f);
float displayedWidth = drawableWidth * f[Matrix.MSCALE_X];
float displayedHeight = drawableHeight * f[Matrix.MSCALE_Y];
矩陣