gpt4 book ai didi

android - SwipeListView 一次只打开一个项目

转载 作者:塔克拉玛干 更新时间:2023-11-01 21:26:50 26 4
gpt4 key购买 nike

这个问题是指在此处找到的 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;
}

其余未提及的代码相同。

非常感谢任何评论,此更改使您不必在扩充列表的 Activity 中实现 SwipeListViewOnTouchListener

最佳答案

缺点:不会关闭由 openAnimate()

打开的行
   BaseSwipeListViewListener swipeListViewListener = new BaseSwipeListViewListener() {
int openItem = -1;

@Override
public void onStartOpen(int position, int action, boolean right) {
super.onStartOpen(position, action, right);

if (openItem > -1)
swipeListView.closeAnimate(openItem);

openItem = position;
}
}

或者更好的方法:

 @Override
public void onStartOpen(int position, int action, boolean right) {
super.onStartOpen(position, action, right);
swipeListView.closeOpenedItems();
}

然后给listView设置监听器:

   swipeListView.setSwipeListViewListener(swipeListViewListener);

关于android - SwipeListView 一次只打开一个项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22604293/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com