请教:如何区别点击事件和滑屏事件,不要通过判断滑动距离的那种判断方式

解决方案 »

  1.   

    你可以在代码中实现GestureDetector的OnGestureListener事件
    在这个接口中onDown(MotionEvent e) 是点击事件
    onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY)是滑屏事件
    你可以参考下GridView pageView = (GridView) LayoutInflater.from(this).inflate(
                                            R.layout.app_grid, null).findViewById(R.id.app_grid);viewFlipper.addView(pageView);
    pageView.setOnTouchListener(this);/**
             * 关键,手势检测器
             */
            public boolean onTouch(View v, MotionEvent event) {
                    return this.detector.onTouchEvent(event);
            }
    源码地址请详见:http://www.eoeandroid.com/forum.php?mod=viewthread&tid=108411
      

  2.   

    我遇到的问题是这样的:
    界面上有listview,既有滑屏,又有onItemClickListener事件,如何处理这个冲突
      

  3.   


    @Override
    public boolean dispatchTouchEvent(MotionEvent ev) {
    // TODO Auto-generated method stub
    mDetector.onTouchEvent(ev);
    mTextView.onTouchEvent(ev);
    mScroll.onTouchEvent(ev);
    return true;
    }在派发事件中对所有的onTouchEvent()事件进行派发,顺序只是谁先处理,没有多大关系
    注意后面一定是return true;因为return true就意味着dispatchTouchEvent会被系统响应
    比如你的可以是这样:@Override
    public boolean dispatchTouchEvent(MotionEvent ev) {
    // TODO Auto-generated method stub
    mDetector.onTouchEvent(ev);//处理ListView的滑屏
    mListView.onTouchEvent(ev);//处理ListView的点击事件包括onItemClickListener
    return true;
    }