While my previous answer does outline the overall problem, it in fact might not be a bug. As pointed out by Generic Holiday Name, mDrawMatrix
should be set to mMatrix
in the configureBounds()
method - which would eliminate this problem/bug/whatever.
HOWEVER, I had to add several lines of code to get configureBounds()
to actually work:
private void configureBounds() {
if (mDrawable == null || !mHaveFrame) {
return;
}
int dwidth = mDrawableWidth;
int dheight = mDrawableHeight;
...
if (dwidth <= 0 || dheight <= 0 || ScaleType.FIT_XY == mScaleType) {
/* If the drawable has no intrinsic size, or we're told to
scaletofit, then we just fill our entire view.
*/
mDrawable.setBounds(0, 0, vwidth, vheight);
mDrawMatrix = null;
} else {
//here's the where mDrawMatrix == mMatrix IF using scaleType.MATRIX
...
}
}
So, in order to actually get this to work the way I expect with 4.2 and below you need to make sure:
mDrawable != null
. This wasn't a problem before, but for my case I wasn't using a drawable so everything was failing (thereturn
statement was hit right away)'dwidth >0 && dheight >0
. This isn't a problem if you have a real drawable, but like I said, I didn't.mHaveFrame = true
. I had no idea what this was - never used it. The only way to set this to true is by callingsetFrame(int, int, int, int)
.
To get my scaling code to work again, I had to add the following:
//potentially a fix for the "bug" that appears in Android 4.3+
//mDrawable cannot be null anymore for getImageMatrix to work---stupid
//therefore the imageview class MUST set a drawable for matrix scaling to work
//so here I am using a "empty" drawable to get around this
ShapeDrawable fakeDrawable = new ShapeDrawable(); //so mDrawable != null
fakeDrawable.setIntrinsicHeight(1); //so dwidth and dheight are > 0
fakeDrawable.setIntrinsicWidth(1);
setImageDrawable(fakeDrawable);
setFrame(0, 0, viewWidth, viewHeight); //setting a frame so mHaveFrame = true
YIKES