Hello,
What exactly do I need to do to add the scale gesture, and is there anything extra I need to do to keep the Click event as well? Thanks.
You need to set TouchListener
with previewView1.SetOnTouchListener(new MyTouchListener(Application.Context));
You need to judge the guesture(click or Pinch & Zoom) by move distance.
Then, you can inherit from ScaleGestureDetector.SimpleOnScaleGestureListener to create a new class & overriding OnScale. Here is simple code.
public class MyScaleGestureDetector : ScaleGestureDetector.SimpleOnScaleGestureListener
{
public override bool OnScale(ScaleGestureDetector detector)
{
//add your code here.
return true;
}
}
internal class MyTouchListener : Java.Lang.Object, View.IOnTouchListener
{
private Context context;
ScaleGestureDetector myScaleGestureDetector;
public MyTouchListener(Context context)
{
this.context = context;
myScaleGestureDetector = new ScaleGestureDetector(context, new MyScaleGestureDetector());
}
public bool OnTouch(View v, MotionEvent e)
{
float MoveDownX=0F;
if (e.Action==MotionEventActions.Down)
{
MoveDownX = e.RawX;
}
if (e.Action==MotionEventActions.Move)
{
//execute the Pinch & Zoom
myScaleGestureDetector.OnTouchEvent(e);
}
if (e.Action==MotionEventActions.Up)
{
float tempDX= e.RawX - MoveDownX;
if (Math.Abs(tempDX)<6)
{
// distance is too low, execute click event.
}
}
return true;
}
}
Best Regards,
Leon Lu
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.