1

In my application, i'm using the following code for holding a map which is downloaded from a server.

<?xml version="1.0" encoding="utf-8"?>

    <ScrollView android:id="@+id/scrollView1" 
        android:layout_height="fill_parent" 
        android:layout_width="fill_parent"
        android:layout_gravity="center"
        android:layout_weight="1.0">

        <ImageView android:id="@+id/mapImageView" 
            android:layout_height="wrap_content"  
            android:layout_centerInParent="true"
            android:layout_width="wrap_content"                 
            android:scaleType="center"/>

    </ScrollView>

currently, i can scroll the image up and down only. I need to have the ability to scroll the image to all directions and also to zoom it in and out. How it can be done? Thanks, Eyal.

eyal
  • 2,379
  • 7
  • 40
  • 54
  • You could for example use WebView instead or take a look at how the gallery application does it: http://android.git.kernel.org/?p=platform/packages/apps/Gallery.git;a=tree – mibollma Jul 03 '11 at 15:05

1 Answers1

3

There's a very simple ImageViewTouch that Sephiroto made based on the Gallery application code : http://blog.sephiroth.it/2011/04/04/imageview-zoom-and-scroll/

I use it in a project and it works perfectly, with pinch-to-zoom and everything you might want. By default, when you set an image to it, the image will be scaled down to fit the screen.

edit : if you want to prevent the automatic image resize, you can change the ImageViewTouchBase.getProperBaseMatrix method to the following :

protected void getProperBaseMatrix(RotateBitmap bitmap, Matrix matrix) {
    float viewWidth = getWidth();
    float viewHeight = getHeight();
    float w = bitmap.getWidth();
    float h = bitmap.getHeight();
    matrix.reset();
    matrix.postConcat(bitmap.getRotateMatrix());
    matrix.postTranslate((viewWidth - w) / 2, (viewHeight - h) / 2);
}

This should center the image without resizing it.

Gregory
  • 4,384
  • 1
  • 25
  • 21
  • When adding an image to this lib, the lib resize the image automaticly. Did you try to avoid this automaticly resize? – eyal Jul 07 '11 at 20:02
  • Yes, I removed it. The method I changed is in my updated post. – Gregory Jul 07 '11 at 20:13
  • Thanks for your help. Now I'm trying to drag the image, before any zooming action, with out the auto resizing but it does not move. How it can be fixed? – eyal Jul 08 '11 at 08:06
  • Just in case, each time you do something a method is called to recenter the image (not sure what the name is), you can either not call it or just let it blank if you want to completely bypass it. – Gregory Jul 08 '11 at 11:11