2017-03-10 24 views

回答

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導入v22.2 +的RecyclerView庫

compile 'com.android.support:recyclerview-v7:22.2.+' 2)實例化的ItemTouchHelper與適當的

SimpleCallbackItemTouchHelper.SimpleCallback simpleItemTouchCallback = new ItemTouchHelper.SimpleCallback(0,ItemTouchHelper.LEFT | ItemT ouchHelper.RIGHT){[...] @Override public void onSwiped(RecyclerView.ViewHolder viewHolder,int swipeDir){//從列表中刪除滑動的項目並通知RecyclerView}}; ItemTouchHelper itemTouchHelper = new ItemTouchHelper(simpleItemTouchCallback); **請注意,SimpleCallback接受您希望啓用拖放操作的指示以及您希望啓用滑動的指示。

3)附加到您的RecyclerViewitemTouchHelper.attachToRecyclerView(recyclerView);

+0

如何在水平回收視圖中使用此功能? –

+0

用這個替換你的水平滾動視圖。 –

+0

我試圖將LinearLayoutManager設置爲水平,但它不工作。 –

相關問題