Created
January 28, 2013 14:41
-
-
Save Cheesebaron/4656031 to your computer and use it in GitHub Desktop.
Y locking ScrollView
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using Android.Content; | |
using Android.Runtime; | |
using Android.Util; | |
using Android.Views; | |
using Android.Widget; | |
namespace Cheesebaron.HorizontalListView | |
{ | |
public class YScrollView : ScrollView | |
{ | |
private float _xDistance, _yDistance, _lastX, _lastY; | |
protected YScrollView(IntPtr javaReference, JniHandleOwnership transfer) : base(javaReference, transfer) | |
{ | |
} | |
public YScrollView(Context context) : base(context) | |
{ | |
} | |
public YScrollView(Context context, IAttributeSet attrs) : base(context, attrs) | |
{ | |
} | |
public YScrollView(Context context, IAttributeSet attrs, int defStyle) : base(context, attrs, defStyle) | |
{ | |
} | |
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: | |
var curX = ev.GetX(); | |
var 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); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment