I am developing an application. In my application I am display images using ImageView
from url using xml parsing. I want to display zoom image when I double touch on the Image, then again double touch on zoomImage, I want to reset image. How to implement in image using Android?
setOnTouchListener(new OnTouchListener(){ @Override public boolean onTouch(View v, MotionEvent event) { mDetector. onTouchEvent(event); return true; }}); I would override the methods in MyGestureDetector and log to logcat like I'm doing on double tap to get a feel for how this works.
After the Math. abs() calls, you're essentially testing if their finger is farther down the screen than it is across the screen. Store the initial down coordinates as member variables and set them during ACTION_DOWN . You declared two floats (touchX and touchY) inside the onTouchEvent method.
This is how you implement a touch listener in Android.
yourImageView.setOnTouchListener(new OnTouchListener()
{
@Override
public boolean onTouch(View v, MotionEvent event)
{
return false;
}
});
To detect double taps you use GestureDetector like this:
1) Make your own GestureDetector, derived from SimpleOnGestureListener and override the methods you're interested in (see google's docs on SimpleOnGestureListener for the exact methods you can override, I've done double tap here):
class MyGestureDetector extends GestureDetector.SimpleOnGestureListener
{
@Override
public boolean onDoubleTapEvent(MotionEvent e)
{
Log.i("Taghere..", "onDoubleTapEvent");
return true;
}
}
2) Create an instance of your gesture detector. I'm making a member variable and instantiating in onCreate.
private GestureDetector mDetector;
mDetector = new GestureDetector(this, new MyGestureDetector());
3) Setup a touch listener on your imageview and route the messages to your gesture detector:
ImageView iv = (ImageView)findViewById(R.id.yourimageviewid);
iv.setOnTouchListener(new OnTouchListener(){
@Override
public boolean onTouch(View v, MotionEvent event)
{
mDetector.onTouchEvent(event);
return true;
}});
I would override the methods in MyGestureDetector and log to logcat like I'm doing on double tap to get a feel for how this works.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With