我想向左滑动recyclerview两侧,右像下面的图像: - 如何刷卡在recyclerview两侧左,右的Android
但我不能做我看到很多图书馆,但我觉得只有一个侧滑动。我希望双方滑动我如何做,这有助于我做到这一点。
在此先感谢
我想向左滑动recyclerview两侧,右像下面的图像: - 如何刷卡在recyclerview两侧左,右的Android
但我不能做我看到很多图书馆,但我觉得只有一个侧滑动。我希望双方滑动我如何做,这有助于我做到这一点。
在此先感谢
你需要的东西是这样的:
@Override
public void onSwiped(RecyclerView.ViewHolder viewHolder, int direction) {
int position = viewHolder.getAdapterPosition();
if (direction == ItemTouchHelper.LEFT){
Log.i("ItemSwipe", "LEFT");
}
else if (direction == ItemTouchHelper.RIGHT){
Log.i("ItemSwipe", "RIGHT");
}
}
onSwiped哪个类是方法? –
下面是工作的代码创建自定义监听SyncedScrollListener并将其分配给两个recycleview。
rv1.setOnScrollListener(new SyncedScrollListener(rv2));
rv2.setOnScrollListener(new SyncedScrollListener(rv1));
public class SyncedScrollListener implements AbsListView.OnScrollListener {
int offset;
int oldVisibleItem = -1;
int currentHeight;
int prevHeight;
private View mSyncedView;
public SyncedScrollListener(View syncedView) {
if (syncedView == null) {
throw new IllegalArgumentException("syncedView is null");
}
mSyncedView = syncedView;
}
public void onScroll(AbsListView view, int firstVisibleItem,
int visibleItemCount, int totalItemCount) {
int[] location = new int[2];
if (visibleItemCount == 0) {
return;
}
if (oldVisibleItem != firstVisibleItem) {
if (oldVisibleItem < firstVisibleItem) {
prevHeight = currentHeight;
currentHeight = view.getChildAt(0).getHeight();
offset += prevHeight;
} else {
currentHeight = view.getChildAt(0).getHeight();
View prevView;
if ((prevView = view.getChildAt(firstVisibleItem - 1)) != null) {
prevHeight = prevView.getHeight();
} else {
prevHeight = 0;
}
offset -= currentHeight;
}
oldVisibleItem = firstVisibleItem;
}
view.getLocationOnScreen(location);
int listContainerPosition = location[1];
view.getChildAt(0).getLocationOnScreen(location);
int currentLocation = location[1];
int blah = listContainerPosition - currentLocation + offset;
mSyncedView.scrollTo(0, blah);
}
public void onScrollStateChanged(AbsListView view, int scrollState) {
// TODO Auto-generated method stub
}
}
它工作在两边? –
是的,我已经在其工作前双方使用这个 –
在哪里我可以添加两侧滑动我没有找到我可以添加的地方 –