ByakuGallery
ByakuGallery copied to clipboard
How to limit imageview's min scale in x
Now i have a picture, it's size is 990 X 18464 , when first load picture into imageview, it's's very small. I onDoubleTap it ,it looks better. I had seen mMaxScale in TouchImageView, but no mMinScale , please help me , thank you
@t2314862168 you can use getMinScale
method to get minimal scale. Take a look at this class TouchImageView.java
You can calculate desired scale and set it to ImageView in method
public void setImageDrawable(Drawable drawable)
.
@Override
public void setImageDrawable(Drawable drawable) {
super.setImageDrawable(drawable);
if(mDrawable != drawable) {
mDrawable = drawable;
if(drawable != null) {
mDrawableIntrinsicWidth = drawable.getIntrinsicWidth();
mDrawableIntrinsicHeight = drawable.getIntrinsicHeight();
setInitialState(); //changed line
} else {
mDrawableIntrinsicWidth = 0;
mDrawableIntrinsicHeight = 0;
}
}
}
public void setInitialState(){
mMatrix.reset();
final float scale= /*CALCULATE DESIRED SCALE*/;
mMatrix.postScale(scale, scale);
final float[] values = new float[9];
mMatrix.getValues(values);
final float freeSpaceHorizontal = (getMeasuredWidth() - (mDrawableIntrinsicWidth * minScale)) / 2F;
final float freeSpaceVertical = (getMeasuredHeight() - (mDrawableIntrinsicHeight * minScale)) / 2F;
mMatrix.postTranslate(freeSpaceHorizontal, freeSpaceVertical);
invalidate();
}