java - how to set default image size in image view with zoom in zoom out? -
i using horizontal scrollview, , when clicking on image buttom of horizontal scrollview, image showing in imageview. functionality working properly. , in image view able zoom image. after zooming, when clicking on next image button of scrollview then, imageview bydefault showing zoomed image. taking zoom of previous image. problem how can remove previous zoom, next image. mean next image must come default size, not zoomed.
here code.
public class viewbuttonactivity extends activity implements onclicklistener, ontouchlistener { imageview imgview; private progressdialog pdialog; public static boolean istouch = false; imagebutton imgbutton1, imgbutton2, imgbutton3, imgbutton4, imgbutton5; horizontalscrollview horizontalscrollview; public imageloader imageloader; public static string[] imageurl = { "http://0-03/_cover.jpg", "http://www.magazine.jpg", "http://large_1.jpg", "http://4.bp.apr2011.jpg", "http://www.theof.com/git.jpg" }; private int mimageheight, mimagewidth; private static final string tag = "touch"; private static final float min_zoom = 1f, max_zoom = 1f; matrix matrix = new matrix(); matrix savedmatrix = new matrix(); static final int none = 0; static final int drag = 1; static final int zoom = 2; int mode = none; pointf start = new pointf(); pointf mid = new pointf(); float olddist = 1f; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.view_button_click_activity); imageloader = new imageloader(getapplicationcontext()); imgview = (imageview) findviewbyid(r.id.image_view); imgbutton1 = (imagebutton) findviewbyid(r.id.imagebutton1); imgbutton2 = (imagebutton) findviewbyid(r.id.imagebutton2); imgbutton3 = (imagebutton) findviewbyid(r.id.imagebutton3); imgbutton4 = (imagebutton) findviewbyid(r.id.imagebutton4); imgbutton5 = (imagebutton) findviewbyid(r.id.imagebutton5); horizontalscrollview = (horizontalscrollview) findviewbyid(r.id.horizontal_scroll_view); imageloader.displayimage(imageurl[0], imgbutton1); imageloader.displayimage(imageurl[1], imgbutton2); imageloader.displayimage(imageurl[2], imgbutton3); imageloader.displayimage(imageurl[3], imgbutton4); imageloader.displayimage(imageurl[4], imgbutton5); imgbutton1.setonclicklistener(this); imgbutton2.setonclicklistener(this); imgbutton3.setonclicklistener(this); imgbutton4.setonclicklistener(this); imgbutton5.setonclicklistener(this); mimageheight = imgview.getwidth(); mimagewidth = imgview.getheight(); imgview.setontouchlistener(this); } public void onclick(view v) { switch (v.getid()) { case r.id.imagebutton1: imageloader.displayimage(imageurl[0], imgview); break; case r.id.imagebutton2: imageloader.displayimage(imageurl[1], imgview); break; case r.id.imagebutton3: imageloader.displayimage(imageurl[2], imgview); break; case r.id.imagebutton4: imageloader.displayimage(imageurl[3], imgview); break; case r.id.imagebutton5: imageloader.displayimage(imageurl[4], imgview); // imgview.setimageresource(r.drawable.img5); break; } } public boolean ontouch(view v, motionevent event) { imageview imgview = (imageview) v; imgview.setscaletype(imageview.scaletype.matrix); float scale; dumpevent(event); switch (event.getaction() & motionevent.action_mask) { case motionevent.action_down: // first finger down savedmatrix.set(matrix); start.set(event.getx(), event.gety()); log.d(tag, "mode=drag"); // write logcat mode = drag; break; case motionevent.action_up: // first finger lifted case motionevent.action_pointer_up: // second finger lifted mode = none; log.d(tag, "mode=none"); break; case motionevent.action_pointer_down: // first , second finger down olddist = spacing(event); log.d(tag, "olddist=" + olddist); if (olddist > 5f) { savedmatrix.set(matrix); midpoint(mid, event); mode = zoom; log.d(tag, "mode=zoom"); } break; case motionevent.action_move: if (mode == drag) { matrix.set(savedmatrix); matrix.posttranslate(event.getx() - start.x, event.gety() - start.y); // create transformation in matrix // of points } else if (mode == zoom) { // pinch zooming float newdist = spacing(event); log.d(tag, "newdist=" + newdist); if (newdist > 5f) { matrix.set(savedmatrix); scale = newdist / olddist; // setting scaling of // matrix...if scale > 1 means // zoom in...if scale < 1 means // zoom out matrix.postscale(scale, scale, mid.x, mid.y); } } break; } imgview.setimagematrix(matrix); return true; } private float spacing(motionevent event) { float x = event.getx(0) - event.getx(1); float y = event.gety(0) - event.gety(1); return floatmath.sqrt(x * x + y * y); } private void midpoint(pointf point, motionevent event) { float x = event.getx(0) + event.getx(1); float y = event.gety(0) + event.gety(1); point.set(x / 2, y / 2); } private void dumpevent(motionevent event) { string names[] = { "down", "up", "move", "cancel", "outside","pointer_down", "pointer_up", "7?", "8?", "9?" }; stringbuilder sb = new stringbuilder(); int action = event.getaction(); int actioncode = action & motionevent.action_mask; sb.append("event action_").append(names[actioncode]); if (actioncode == motionevent.action_pointer_down || actioncode == motionevent.action_pointer_up) { sb.append("(pid ").append(action >> motionevent.action_pointer_id_shift); sb.append(")"); } sb.append("["); (int = 0; < event.getpointercount(); i++) { sb.append("#").append(i); sb.append("(pid ").append(event.getpointerid(i)); sb.append(")=").append((int) event.getx(i)); sb.append(",").append((int) event.gety(i)); if (i + 1 < event.getpointercount()) sb.append(";"); } sb.append("]"); log.d("touch events ---------", sb.tostring()); }
}
presumably have reset original value of matrix contains current state of transformation (which includes zoom)? see keep track of matrix, what's standing in way resetting old value when advance next image during onclick()?
Comments
Post a Comment