Question

today I set up the new Android JB 4.3 on my Nexus 7 and i tried to run my application.

Everythings works like it should except one little thing about ImageViews with ScaleType.MATRIX.

Basically what i have in my application is a ImageView as background and accordingly to a ViewPager callbacks i move the focused part of the image updating the Matrix i gave to the imageView using setImageMatix( Matrix matrix ).

the problem seems to be that i can't update the matrix anymore, i just have to instantiate a new one a pass it to the ImageView.

i managed to work around it instantiating everytime a new Matrix but it seems awfully memory expensive compared to the old version.

is this a BUG? is there a way to udpate the Matrix? ( i by the way already tried to invalidate() the ImageView ecc. )

NOT WORKING

    private void updateMatrix( final int page, final double offset ) {          
        double pagePosition = page + offset;

        Matrix matrix = imageView.getImageMatrix();
        matrix.setScale( scale, scale );
        matrix.postTranslate( - (float) ( pagePosition * pageWidth ) , 0 );

        imageView.setImageMatrix( matrix );

        imageView.invalidate();
    }

WORKING

    private void updateMatrix( final int page, final double offset ) {          
        double pagePosition = page + offset;

        Matrix matrix = new Matrix();
        matrix.setScale( scale, scale );
        matrix.postTranslate( - (float) ( pagePosition * pageWidth ) , 0 );

        imageView.setImageMatrix( matrix );

        imageView.invalidate();
    }

EDIT:

in the first case the image is shown at the top left corner of the ImageView without any scale or translate applied to it, like if the matrix is back to identity.

Was it helpful?

Solution

Just preserve your Matrix as field instead of retrieving it from ImageView and you'll be happy :)

OTHER TIPS

There may be a bug with ImageView scaling starting with 4.3. See my question and answer about this bug.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top