在图库中实现垂直滑动时出现问题
我在 android 开发者小组中提出了类似的问题,但尚未收到回复,所以我想我应该在这里碰碰运气。
我想在画廊上实现垂直滑动并且我让它工作......有点。我对 Gallery 进行了子类化,以便可以重写 onFling 和 onDown 方法。
以下是我用来重写这些方法的代码:
@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY)
{
if (m_curTouchPos == NO_CURRENT_TOUCH_POS || m_callback == null)
return super.onFling(e1, e2, velocityX, velocityY);
float e1x = e1.getX();
float e1y = e1.getY();
float e2x = e2.getX();
float e2y = e2.getY();
float offPath = Math.abs(e1x - e2x);
float distance = Math.abs(e1y - e2y);
if (offPath < s_swipeMaxOffPath &&
//Math.abs(velocityY) >= s_swipeMinVelocity &&
distance >= s_swipeMinDistance)
{
if (e1y > e2y)
{
m_callback.onSwipeUp(m_curTouchPos);
//return true;
}
else if (e2y > e1y)
{
//TODO: IMPLEMENT THIS
//m_callback.onSwipeDown(m_curTouchPos);
//return true;
}
}
m_curTouchPos = NO_CURRENT_TOUCH_POS;
return super.onFling(e1, e2, velocityX, velocityY);
}
@Override
public boolean onDown(MotionEvent eve)
{
m_curTouchPos = pointToPosition((int)eve.getX(), (int)eve.getY());
return super.onDown(eve);
}
问题是,当我进行垂直滑动时,onFling 不会被调用...为了进入 onFling 方法,我必须按下图库中的一个项目,然后滑动慢慢地向左或向右一点,然后垂直滑动。
水平滑动始终会进入 onFling 方法。
关于如何让它发挥作用有什么想法吗?
I asked a similar question in the android developers group but haven't received a response yet, so I figured I'd try my luck here.
I want to implement a vertical swipe on a Gallery and I have it working... sort of. I subclassed Gallery so that I could override the onFling and onDown methods.
Here is the code I used to override these methods:
@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY)
{
if (m_curTouchPos == NO_CURRENT_TOUCH_POS || m_callback == null)
return super.onFling(e1, e2, velocityX, velocityY);
float e1x = e1.getX();
float e1y = e1.getY();
float e2x = e2.getX();
float e2y = e2.getY();
float offPath = Math.abs(e1x - e2x);
float distance = Math.abs(e1y - e2y);
if (offPath < s_swipeMaxOffPath &&
//Math.abs(velocityY) >= s_swipeMinVelocity &&
distance >= s_swipeMinDistance)
{
if (e1y > e2y)
{
m_callback.onSwipeUp(m_curTouchPos);
//return true;
}
else if (e2y > e1y)
{
//TODO: IMPLEMENT THIS
//m_callback.onSwipeDown(m_curTouchPos);
//return true;
}
}
m_curTouchPos = NO_CURRENT_TOUCH_POS;
return super.onFling(e1, e2, velocityX, velocityY);
}
@Override
public boolean onDown(MotionEvent eve)
{
m_curTouchPos = pointToPosition((int)eve.getX(), (int)eve.getY());
return super.onDown(eve);
}
The problem is that onFling doesn't get called when I do a vertical swipe... In order to get into the onFling method I have to press on an item in the gallery, slide it slowly a little to the left or right, and then swipe vertically.
Horizontal swipes always get into the onFling method.
Any ideas on how to get this to work?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好的,我找到了答案... onDown() 方法需要返回 true。调用 return super.onDown(eve) 导致它失败,因为默认实现返回 false。
我在 StackOverflow 上的另一篇文章中找到了答案:
Android: GestureDetector 不起作用 (gestureDetector .onTouchEvent(event) 始终为 false) 与选项卡 (TabActivity, Tabwidget)
Ok, I have found the answer... The onDown() method needs to return true. The call to return super.onDown(eve) was causing it to fail because the default implementation returns false.
I found the answer in another post here on StackOverflow:
Android: GestureDetector not working (gestureDetector.onTouchEvent(event) always false) with Tabs (TabActivity, Tabwidget)