其他分享
首页 > 其他分享> > Listview没有滚动浏览android中的视图鳍状肢

Listview没有滚动浏览android中的视图鳍状肢

作者:互联网

视图鳍状肢有4个列表视图.当我使用在视图鳍状肢上实现的手势监听器翻转视图鳍状肢时,它工作正常.但我无法滚动列表视图,因为触摸事件无法从视图鳍状态向下流入列表视图.请提供解决方案.

private class MyViewFlipper extends ViewFlipper implements OnGestureListener {
    GestureDetector gestureScanner = new GestureDetector(this);
    Context context;

    public MyViewFlipper(Context context) {
        super(context);
        this.context=context;
    }

    @Override
    public boolean onInterceptTouchEvent(MotionEvent event) { 
        return gestureScanner.onTouchEvent(event);
    }

    @Override
    public boolean onTouchEvent(MotionEvent event) {  
        return gestureScanner.onTouchEvent(event);
    }

    @Override
    public boolean onDown(MotionEvent arg0) {
        return true;
    }

    @Override
    public boolean 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) {
                this.setOutAnimation(AnimationUtils.loadAnimation(context,R.anim.push_left_out));
                this.setInAnimation(AnimationUtils.loadAnimation(context,R.anim.push_left_in));
                this.showNext();
                return true;
            } else if (e2.getX() - e1.getX() > SWIPE_MIN_DISTANCE &&
                       Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) {
                this.setOutAnimation(AnimationUtils.loadAnimation(context,R.anim.push_right_out));
                this.setInAnimation(AnimationUtils.loadAnimation(context,R.anim.push_right_in));
                this.showPrevious();
                return true;
            } else if (e1.getY() - e2.getY() > SWIPE_MIN_DISTANCE &&
                       Math.abs(velocityY) > SWIPE_THRESHOLD_VELOCITY) {
                return true;
            } else if (e2.getY() - e1.getY() > SWIPE_MIN_DISTANCE &&
                       Math.abs(velocityY) > SWIPE_THRESHOLD_VELOCITY) {
                return true;
            }
       } catch (Exception e) {
            e.printStackTrace();
            //Toast.makeText(context, "Error Occurred", Toast.LENGTH_LONG);
       }
       return false;
    }

    @Override
    public void onLongPress(MotionEvent e) {

    }

    @Override
    public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
        //I want this event to be handled by list view
        this.getCurrentView().findViewWithTag("hierarchy_list").dispatchTouchEvent(e1);

        Log.i(LOG_TAG, "Scroll");
        return false;
    }

    @Override
    public void onShowPress(MotionEvent e) {

    }

    @Override
    public boolean onSingleTapUp(MotionEvent e) {
        //DO something  
        return false;
    }
}

解决方法:

@Override
public boolean onInterceptTouchEvent(MotionEvent event) { 
    gestureScanner.onTouchEvent(event);
    return false;
}

@Override
public boolean onTouchEvent(MotionEvent event) {  
    gestureScanner.onTouchEvent(event);
    return false; 
}

希望事件将传递下去.

标签:android,listener,listview,gesture
来源: https://codeday.me/bug/20190705/1382991.html