我想在第一个单元格中显示删除选项,在水平回收视图的滚动滚动上,如在垂直列表视图中,可以选择删除或向左或向右滑动项目上的其他选项。有什么例子我能实现吗?
答案 0 :(得分:1)
检查此链接,您可能会得到解决方案, https://github.com/daimajia/AndroidSwipeLayout
As of v22.2.0, the Android support team has included an ItemTouchHelper class that makes swipe-to-dismiss and drag-and-drop pretty simple. This may not be as full-featured as some of the libraries out there, but it comes directly from the Android team.
1)更新build.gradle以导入RecyclerView库的v22.2。+
compile 'com.android.support:recyclerview-v7:22.2.+'
2)使用适当的
SimpleCallbackItemTouchHelper.SimpleCallback simpleItemTouchCallback = new ItemTouchHelper.SimpleCallback(0, ItemTouchHelper.LEFT | ItemTouchHelper.RIGHT) {
[...]
@Override
public void onSwiped(RecyclerView.ViewHolder viewHolder, int swipeDir) {
//Remove swiped item from list and notify the RecyclerView
}
};
ItemTouchHelper itemTouchHelper = new ItemTouchHelper(simpleItemTouchCallback)
请注意,SimpleCallback会引导您要启用拖放的路线以及要启用滑动的路线。
3)附加到RecyclerViewitemTouchHelper.attachToRecyclerView(recyclerView);