3

i have one image in my xml file in android project, i need to zoom it when i click on it. can anybody help me out what code should i write to make my image zoom .

following is my xml code :

main.xml :

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="120dp"
        android:layout_height="120dp"

        android:src="@drawable/rtt" />



</RelativeLayout>
sonia
  • 405
  • 2
  • 7
  • 23
  • Possible duplicate of http://stackoverflow.com/questions/5203702/zoom-image-on-image-click-event Google hard before you post any question here ! – Aakash Anuj Jan 25 '13 at 12:51
  • Take a look at this android developer page: http://developer.android.com/training/animation/zoom.html It explains how to perform animations like zooming in on a view. – BBB Jan 25 '13 at 12:46
  • You could use my library: [PhotoView](https://github.com/chrisbanes/PhotoView) – Chris Banes Jan 25 '13 at 12:44
  • Try this: http://stackoverflow.com/questions/10630373/android-image-view-pinch-zooming – Shai Ben Shimol Jan 26 '13 at 16:09

1 Answers1

0

try using the setScaleX and setScaleY methods

imageview1.setScaleX((float)(1));
imageview1.setScaleY((float)(1));

to zoom in use a float that is more than 1, to zoom out use a float that is less that 1, to stop zooming in/out use 1 here is an example :

imageview1.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View _view) {
        isZoomOn = !isZoomOn;
        if (isZoomOn) {
            imageview1.setScaleX((float)(1.5d));
            imageview1.setScaleY((float)(1.5d));
        }
        else {
            imageview1.setScaleX((float)(1));
            imageview1.setScaleY((float)(1));
        }
    }
});
Omar Hemaia
  • 188
  • 10