更新时间:2022-12-20 16:47:54
当我在listview上有一个侦听器时,scrollview不起作用.但是当我没有听众时,滑动就不起作用
When I have a listener on listview, the scrollview doesnt work. But when I don't have a listener, the swipe doesn't work
Easter
的OnTouch
方法有问题,我不知道它的逻辑,但是您可以在OnTouch
中自己实现此功能.
It has something wrong with Easter
's OnTouch
method, I dont know its logic but you could do it by yourself in OnTouch
to implement this feature.
您可以在整个FirstFragment
布局中使用SetOnTouchListener
方法,并在OnTouch
方法中实现您的逻辑,这是我的代码:
You could use SetOnTouchListener
method for your whole FirstFragment
layout, and implement your logic in your OnTouch
method, here is my code :
var view = base.OnCreateView(inflater, container, savedInstanceState);
......
view.SetOnTouchListener(this);
//model?.SetOnTouchListener(this);
//listView?.SetOnTouchListener(this);
float mPosX = 0;
float mCurPosX = 0;
float mPosY = 0;
float mCurPosY = 0;
public bool OnTouch(View v, MotionEvent e)
{
switch (e.Action)
{
case MotionEventActions.Down:
mPosX = e.GetX();
mCurPosX = mPosX;
mPosY = e.GetY();
mCurPosY = mPosY;
break;
case MotionEventActions.Move:
mCurPosX = e.GetX();
mCurPosY = e.GetY();
float xDistance = Math.Abs(mCurPosX - mPosX);
float yDistance = Math.Abs(mCurPosY - mPosY);
if (xDistance > yDistance && mCurPosX - mPosX > 0)//Swip Right
{
DoSwipe("RIGHT");
}
else if (xDistance > yDistance && mCurPosX - mPosX < 0)//Swip Left
{
DoSwipe("LEFT");
}
break;
default:
break;
}
return true;
}
效果类似于此.