0

我有一个水平列表,滑动关闭工作,除了滑动关闭优先于滚动,即如果我从左向右滑动但在最轻微的角度上它会认为我试图滑动关闭项目而不是滚动列表。我认为最简单的方法是让它反过来,但不知道如何改变它或者是否有更好的方法

我修改了 Lucas Rocha 的twowayview和 Roman Nurik/Tim Roes swipedismissundolist

我不确定所有这些代码是否都在我应该寻找的地方,但据我所知,它是相关的。

主要活动

   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;

            }

    };

滑动关闭

/**
 * 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) {...

双向视图

    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);
        }
    }
}
4

1 回答 1

0

我在这里发现了一个非常重复的问题

我将动作向下和动作移动代码添加到 swipedismiss 的 onTouch 方法中

     @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;
}
于 2013-07-22T12:59:32.930 回答