0
我有一個水平列表刷卡解僱工作,除了滑動解僱優先滾動,即如果我從左到右滑動,但在最輕微的角度,它會認爲我試圖刷卡解僱一個項目,而不是滾動列表。 我覺得這個最簡單的辦法是各地擁有它的其他方式,但不知道如何去改變它或是否有更好的辦法觸摸監聽器優先於列表滾動監聽器
我修改盧卡斯Rocha的twowayview和羅馬Nurik /蒂姆魚卵swipedismissundolist
我不確定是否所有的代碼都是我應該看的地方,但是我可以告訴它相關的。
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);
}
}
}