我想向左滑動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
}
}
它工作在兩邊? –
是的,我已經在其工作前雙方使用這個 –
在哪裏我可以添加兩側滑動我沒有找到我可以添加的地方 –