首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
社区首页 >问答首页 >在图库中实现垂直滑动时出现问题

在图库中实现垂直滑动时出现问题
EN

Stack Overflow用户
提问于 2011-02-24 08:47:51
回答 1查看 1.7K关注 0票数 1

我在android开发者小组中问了一个类似的问题,但还没有得到回应,所以我想我应该在这里碰碰运气。

我想实现一个画廊的垂直滑动,我有它的工作…说大也大吧。我创建了Gallery的子类,这样我就可以覆盖onFling和onDown方法。

下面是我用来覆盖这些方法的代码:

代码语言:javascript
代码运行次数:0
运行
复制
@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方法。

你有什么办法让它工作吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2011-03-01 08:05:49

好了,我找到答案了……onDown()方法需要返回true。对return super.onDown(eve)的调用导致它失败,因为默认实现返回false。

我在StackOverflow上的另一篇文章中找到了答案:

Android: GestureDetector not working (gestureDetector.onTouchEvent(event) always false) with Tabs (TabActivity, Tabwidget)

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/5099177

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档