Adr*_*lar 13 android swipe ontouchlistener swipe-gesture
这个问题涉及这里找到的SwipeListView组件:https://github.com/47deg/android-swipelistview
在尝试了我在网上找到的几个实现和修复后,我决定稍微修改一下这些来源.
我会在这里发布这个,因为我知道这是一个已知的问题,我发现的所有版本最终都有一些问题.
SwipeListViewTouchListener.java 遭受了以下变化:
...
/**
* Create reveal animation
*
* @param view affected view
* @param swap If will change state. If "false" returns to the original
* position
* @param swapRight If swap is true, this parameter tells if movement is toward
* right or left
* @param position list position
*/
private void generateRevealAnimate(final View view, final boolean swap, final boolean swapRight, final int position) {
int moveTo = 0;
if (opened.get(position)) {
if (!swap) {
moveTo = openedRight.get(position) ? (int) (viewWidth - rightOffset) : (int) (-viewWidth + leftOffset);
}
} else {
if (swap) {
moveTo = swapRight ? (int) (viewWidth - rightOffset) : (int) (-viewWidth + leftOffset);
}
}
final boolean aux = !opened.get(position);
if(swap) {
opened.set(position, aux);
openedRight.set(position, swapRight);
}
animate(view).translationX(moveTo).setDuration(animationTime).setListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
swipeListView.resetScrolling();
if (swap) {
if (aux) {
swipeListView.onOpened(position, swapRight);
} else {
swipeListView.onClosed(position, openedRight.get(position));
}
}
// if (aux || !swap) {
// resetCell();
// }
}
});
}
...
/**
* Close all opened items
*/
void closeOtherOpenedItems() {
if (opened != null && downPosition != SwipeListView.INVALID_POSITION) {
int start = swipeListView.getFirstVisiblePosition();
int end = swipeListView.getLastVisiblePosition();
for (int i = start; i <= end; i++) {
if (opened.get(i) && i != downPosition) {
closeAnimate(swipeListView.getChildAt(i - start).findViewById(swipeFrontView), i);
}
}
}
}
...
/**
* @see View.OnTouchListener#onTouch(android.view.View,
* android.view.MotionEvent)
*/
@Override
public boolean onTouch(View view, MotionEvent motionEvent) {
...
closeOtherOpenedItems();
view.onTouchEvent(motionEvent);
return true;
}
Run Code Online (Sandbox Code Playgroud)
未提及的其余代码是相同的.
任何评论都高度赞赏,这些更改阻止您必须SwipeListViewOnTouchListener在膨胀列表的活动中实现.
| 归档时间: |
|
| 查看次数: |
4511 次 |
| 最近记录: |