Question

I have got a horizontal list with swipe dismiss working except the swipe dismiss takes precendence over scrolling ie if I swipe from left to right but on the slightest angle it will think that im trying to swipe dismiss an item instead of scrolling the list along. I think the easiest approach to this would be to have it the other way around but have no idea how to change it or if there is a better way

I've modified Lucas Rocha's twowayview and Roman Nurik/Tim Roes swipedismissundolist

I'm not sure if all this code is where i should be looking but from what i can tell it's relevant.

mainactivity

   listView = (TwoWayView) findViewById(R.id.listView1);


    //need to add in emptyview and list view to show and gone them when emtpy/full


   imageAdapter = new ImageAdapter(this, products,emptyview,listView);


    listView.setAdapter(imageAdapter);


    VSwipeDismissList.OnDismissCallback callback = new VSwipeDismissList.OnDismissCallback() {
        @Override
        public VSwipeDismissList.Undoable onDismiss(AbsListView listView, final int position) {
            // Delete the item from your adapter (sample code):

            imageAdapter.remove(position);
            return null;

            }

    };

swipedismiss

/**
 * Returns an {@link android.widget.AbsListView.OnScrollListener} to be
 * added to the {@link ListView} using
 * {@link ListView#setOnScrollListener(android.widget.AbsListView.OnScrollListener)}.
 * If a scroll listener is already assigned, the caller should still pass
 * scroll changes through to this listener. This will ensure that this
 * {@link SwipeDismissListViewTouchListener} is paused during list view
 * scrolling.</p>
 *
 * @see {@link SwipeDismissListViewTouchListener}
 */
private AbsListView.OnScrollListener makeScrollListener() {
    return new AbsListView.OnScrollListener() {
        @Override
        public void onScrollStateChanged(AbsListView absListView, int scrollState) {
            setEnabled(scrollState != AbsListView.OnScrollListener.SCROLL_STATE_TOUCH_SCROLL);
        }

        @Override
        public void onScroll(AbsListView absListView, int i, int i1, int i2) {
        }
    };
}

@Override
public boolean onTouch(View view, MotionEvent motionEvent) {...

twowayview

    private boolean maybeStartScrolling(int delta) {
    final boolean isOverScroll = (mOverScroll != 0);
    if (Math.abs(delta) <= mTouchSlop && !isOverScroll) {
        return false;
    }

    if (isOverScroll) {
        mTouchMode = TOUCH_MODE_OVERSCROLL;
    } else {
        mTouchMode = TOUCH_MODE_DRAGGING;
    }

    // Time to start stealing events! Once we've stolen them, don't
    // let anyone steal from us.
    final ViewParent parent = getParent();
    if (parent != null) {
        parent.requestDisallowInterceptTouchEvent(true);
    }

    cancelCheckForLongPress();

    setPressed(false);
    View motionView = getChildAt(mMotionPosition - mFirstPosition);
    if (motionView != null) {
        motionView.setPressed(false);
    }

    reportScrollStateChange(OnScrollListener.SCROLL_STATE_TOUCH_SCROLL);

    return true;
}

private void maybeScroll(int delta) {
    if (mTouchMode == TOUCH_MODE_DRAGGING) {
        handleDragChange(delta);
    } else if (mTouchMode == TOUCH_MODE_OVERSCROLL) {
        handleOverScrollChange(delta);
    }
}

private void handleDragChange(int delta) {
    // Time to start stealing events! Once we've stolen them, don't
    // let anyone steal from us.
    final ViewParent parent = getParent();
    if (parent != null) {
        parent.requestDisallowInterceptTouchEvent(true);
    }

    final int motionIndex;
    if (mMotionPosition >= 0) {
        motionIndex = mMotionPosition - mFirstPosition;
    } else {
        // If we don't have a motion position that we can reliably track,
        // pick something in the middle to make a best guess at things below.
        motionIndex = getChildCount() / 2;
    }

    int motionViewPrevStart = 0;
    View motionView = this.getChildAt(motionIndex);
    if (motionView != null) {
        motionViewPrevStart = (mIsVertical ? motionView.getTop() : motionView.getLeft());
    }

    boolean atEdge = scrollListItemsBy(delta);

    motionView = this.getChildAt(motionIndex);
    if (motionView != null) {
        final int motionViewRealStart =
                (mIsVertical ? motionView.getTop() : motionView.getLeft());

        if (atEdge) {
            final int overscroll = -delta - (motionViewRealStart - motionViewPrevStart);
            updateOverScrollState(delta, overscroll);
        }
    }
}
Was it helpful?

Solution

I found a pretty much duplicate question here

i added the action down and action move code to the onTouch method of swipedismiss

     @Override
   public boolean onInterceptTouchEvent(MotionEvent ev) {
    switch (ev.getAction()) {
    case MotionEvent.ACTION_DOWN:
        xDistance = yDistance = 0f;
        lastX = ev.getX();
        lastY = ev.getY();
        break;
    case MotionEvent.ACTION_MOVE:
        final float curX = ev.getX();
        final float curY = ev.getY();
        xDistance += Math.abs(curX - lastX);
        yDistance += Math.abs(curY - lastY);
        lastX = curX;
        lastY = curY;
        if(xDistance > yDistance)
            return false;
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top