问题
In Android using ImageView and Matrix, I want to scale an image to fit in the display area.
Then using pinch, a user can zoom the image.
Using setScaleType(ImageView.ScaleType.FIT_CENTER)
I can fit my image in display area. But when I use setScaleType(ImageView.ScaleType.MATRIX)
, to start zooming the image, the image gets reset to default size.
So my question is how to find a scale matrix which will give same effect as
setScaleType(ImageView.ScaleType.FIT_CENTER)
.
回答1:
You need to use mMatrix.setRectToRect
and Matrix.ScaleToFit.CENTER
with your image coordinates and your view coordinates as the source and destination rectangles.
mMatrix.setRectToRect(new RectF(0,0,mImageView.getMeasuredWidth(),mImageView.getMeasuredHeight()),new RectF(0,0,mImageView.getParent().getMeasuredWidth(),mImageView.getParent().getMeasuredHeight()),Matrix.ScaleToFit.CENTER);
来源:https://stackoverflow.com/questions/9766052/how-to-get-setscaletypeimageview-scaletype-fit-center-effect-using-setscaletyp