我能够在列表视图上执行滑动。我想从L - >滑动时显示一种颜色。 R和从R上滑动时的不同颜色 - > L.任何人都可以帮助我如何实现这一目标。目前我使用下面的代码来识别手势。
public class GestureListener : Java.Lang.Object, GestureDetector.IOnGestureListener
{
public delegate void SwipeLeftEventHandler(MotionEvent first, MotionEvent second);
public event SwipeLeftEventHandler SwipeLeftEvent;
public delegate void SwipeRightEvetnHandler(MotionEvent first, MotionEvent second);
public event SwipeRightEvetnHandler SwipeRightEvent;
//public event Action LeftEvent;
//public event Action RightEvent;
private static int SWIPE_MAX_OFF_PATH = 300;
private static int SWIPE_MIN_DISTANCE = 100;
private static int SWIPE_THRESHOLD_VELOCITY = 10;
public GestureListener()
{
}
public bool OnFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY)
{
try
{
if (Math.Abs(e1.GetY() - e2.GetY()) > SWIPE_MAX_OFF_PATH)
return false;
// right to left swipe
if (e1.GetX() - e2.GetX() > SWIPE_MIN_DISTANCE && Math.Abs(velocityX) > SWIPE_THRESHOLD_VELOCITY && SwipeLeftEvent /*LeftEvent*/ != null)
SwipeLeftEvent(e1, e2); //LeftEvent(); //Toast.MakeText(view.Context, "Left Swipe", ToastLength.Short).Show();
else if (e2.GetX() - e1.GetX() > SWIPE_MIN_DISTANCE && Math.Abs(velocityX) > SWIPE_THRESHOLD_VELOCITY && SwipeRightEvent /*RightEvent*/ != null)
SwipeRightEvent(e1, e2); //RightEvent(); // Toast.MakeText(view.Context, "Right Swipe", ToastLength.Short).Show();
}
catch (Exception e)
{
// nothing
}
return false;
}
public bool OnDown(MotionEvent e)
{
return true;
}
public void OnLongPress(MotionEvent e)
{
}
public bool OnScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY)
{
return true;
}
public void OnShowPress(MotionEvent e)
{
}
public bool OnSingleTapUp(MotionEvent e)
{
return true;
}
}
答案 0 :(得分:0)
您应该可以通过this.setBackgroundColor(YOURCOLORHERE)
更改背景颜色,其中this
是检测到的行。这是一个similar question,请告诉我这是否解决了您的问题。