Pinch Zoom And Onclicklistener For Same Layout Not Working In Android
I've tried to implement PinchZoom custom Layout in Android based on the below link. https://gist.github.com/anorth/9845602 At the same time implemented onClickListener for the same
Solution 1:
Try this may help you
No need to set onClick() method onTouch() will handle both the case.
package com.example.demo;
import android.app.Activity;
import android.os.Bundle;
import android.view.GestureDetector;
import android.view.GestureDetector.SimpleOnGestureListener;
import android.view.Menu;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import android.widget.ImageButton;
publicclassMainActivityextendsActivity {
private GestureDetector gestureDetector;
@OverrideprotectedvoidonCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
gestureDetector = newGestureDetector(this, newSingleTapConfirm());
ImageButtonimageButton= (ImageButton) findViewById(R.id.img);
imageButton.setOnTouchListener(newOnTouchListener() {
@OverridepublicbooleanonTouch(View arg0, MotionEvent arg1) {
if (gestureDetector.onTouchEvent(arg1)) {
// single tapreturntrue;
} else {
// your code for move and drag
}
returnfalse;
}
});
}
privateclassSingleTapConfirmextendsSimpleOnGestureListener {
@OverridepublicbooleanonSingleTapConfirmed(MotionEvent event) {
returntrue;
}
}
}
Post a Comment for "Pinch Zoom And Onclicklistener For Same Layout Not Working In Android"