我正在xamarin工作室创建一个应用程序,我对listview有疑问。 默认ListView工作正常,List是可滚动的,我可以上去下去。
我创造了动画 - 我将手指向左移动 - 天变为昨天并向右移动,白天变为明天。当我制作这个动画时,我的listview不可滚动;我有这个代码:
public bool OnTouch(View v, MotionEvent e)
{
switch (e.Action)
{
case MotionEventActions.Down:
_lastX = 0;
_lastY = 0;
_viewX = (int)e.GetX ();
_viewY = (int)e.GetY ();
break;
case MotionEventActions.Up:
if (Math.Abs (_lastX) > 100) {
if (_lastX > 0) {
date = date.AddDays (-1);
DayList.Adapter = new HourInDayAdapter (this, hours, date);
} else {
date = date.AddDays (1);
DayList.Adapter = new HourInDayAdapter (this, hours, date);
}
} else {
Toast.MakeText (this, "text", ToastLength.Short).Show ();
}
break;
case MotionEventActions.Move:
var left = (int)(e.RawX - _viewX);
var down = (int)(e.RawY - _viewY);
_lastY = down;
_lastX = left;
break;
}
return true;
}
这是C# 我想,我应该为MotionEventActions.Move添加一些方法,但我不知道哪种方法; s
答案 0 :(得分:0)
没有人知道解决方案?
我做到了:
case MotionEventActions.Move:
var left = (int)(e.RawX - _viewX);
var down2 = (int)(_lastY - e.GetY ());
DayList.SmoothScrollBy (down2, 0);
_lastY = (int)e.GetY();
_lastX = left;
break;
}
答案 1 :(得分:0)
实际上我建议您在GestureDetector
内使用OnTouch
,这样您就可以告诉"当物品被向左或向右滑动时。 GestureDetector
是一个允许您识别某些动作模式的类。
您可以继承其中一个标准检测器,例如GestureDetector.SimpleOnGestureListener
即
gestureDetector = new GestureDetector(context, YourGestureDetector);
public override bool OnTouch(View v, MotionEvent e)
{
if (gestureDetector.OnTouchEvent(e) && e.Action != MotionEventActions.Down)
{
//you have detected the gesture you were looking for
//Do something about it
return true; //because you want to notify that you handled the event so it won't propogare further (optional, depending on what behavior you want)
}
return base.OnTouch(v, e);
}
以下是探测器实现的示例:
class YourGestureDetector : GestureDetector.SimpleOnGestureListener
{
//always return true in OnDown
public override bool OnDown(MotionEvent e)
{
return true;
}
public override bool OnScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY)
{
//detects scrolling motion. return true so it will be picked up by your detector
}
public override bool OnFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY)
{
//detects "swiping" motion. return true so it will be picked up by your detector
}
}