Open whuBobCat opened 6 years ago
修改如下,当layout的宽大于高的时候,测试没有问题,使用largeImageView.setScale(largeImageView.getFitScale()); 设置图片缩放比例时,能够将图片完整显示
largeImageView.setScale(largeImageView.getFitScale());
设置 0.9 的原因是:如果不设置,则会感觉图片占得太满,0.9 看起来刚刚好
private void initFitImageScale(int imageWidth, int imageHeight) { final int layoutWidth = getMeasuredWidth(); final int layoutHeight = getMeasuredHeight(); if (imageWidth < imageHeight) { fitScale = 0.9f * imageWidth / imageHeight * layoutHeight / layoutWidth; } else { fitScale = 0.9f; } minScale = 0.25f; maxScale = 1.0f * imageWidth / layoutWidth; float a = (0.9f * imageWidth / layoutWidth) * layoutHeight / imageHeight; float density = getContext().getResources().getDisplayMetrics().density; maxScale = maxScale * density; if (maxScale < 4) { maxScale = 4; } if (minScale > a) { minScale = a; } if (criticalScaleValueHook != null) { minScale = criticalScaleValueHook.getMinScale(this, imageWidth, imageHeight, minScale); maxScale = criticalScaleValueHook.getMaxScale(this, imageWidth, imageHeight, maxScale); } }
修改如下,当layout的宽大于高的时候,测试没有问题,使用
largeImageView.setScale(largeImageView.getFitScale());
设置图片缩放比例时,能够将图片完整显示