I need to create a custom view extending HorizontalScrollView class, to intercept it's touch event. So I converted this code (Second answer) as follows:
public class CustomScrollView : HorizontalScrollView
{
private float xDistance, yDistance, lastX, lastY;
public CustomScrollView(Context context, IAttributeSet attrs) : base(context, attrs)
{
}
public override bool OnInterceptTouchEvent(MotionEvent ev)
{
switch (ev.Action)
{
case MotionEventActions.Down:
xDistance = yDistance = 0f;
lastX = ev.GetX();
lastY = ev.GetY();
break;
case MotionEventActions.Move:
float curX = ev.GetX ();
float curY = ev.GetY ();
xDistance += Math.Abs (curX - lastX);
yDistance += Math.Abs (curY - lastY);
lastX = curX;
lastY = curY;
if (xDistance > yDistance) {
return false;
}
break;
}
return base.OnInterceptTouchEvent(ev);
}
}
It's throwing a "Inflating Class" error. What is the problem with this code?