Buffalo
Buffalo

Reputation: 4052

Simple ImageView zooming

I'm trying to build a screen that shows a bunch of thumbnails at the bottom along with a full size version of the photos.

The thumbnails are (indirect) children of a HorizontalScrollView and the full size pictures are added as ImageViews of Fragments in a ViewPager.

What is the simplest way of zooming in on an ImageView? Zooming will use a fixed factor.

I've been unable to locate the Android Gallery source code, which might help me.

public boolean onDoubleTap(MotionEvent event) {

    Log.e("test", "on double tap; event: "+ event);

    Matrix m = new Matrix();
    m.setScale(1.25f, 1.25f);
    clickedImageView.setImageMatrix(m);
    clickedImageView.invalidate();
    clickedImageView.refreshDrawableState();
    Log.e("test", "set image matrix after double tap event");

    return true; // indicate event was handled              
}

Upvotes: 1

Views: 460

Answers (1)

skyrift
skyrift

Reputation: 743

That code looks like it should work, just make sure you set

android:scaleType="matrix"

in the xml for the ImageView, or

clickedImageView.setScaleType(ImageView.ScaleType.MATRIX);

if you want to do it in the code. Otherwise the matrix you have set will not be applied.

Upvotes: 3

Related Questions