轻扫解雇的RecyclerView [英] Swipe to Dismiss for RecyclerView

查看:141
本文介绍了轻扫解雇的RecyclerView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我以前 SwipeToDismiss 库,但现在我想迁移到RecyclerView,事情就不那么明显了,你知道任何替代这个LIB?任何想法如何从从头开始实现它?

I used to SwipeToDismiss library but now I'm trying to migrate to RecyclerView and things are not so obvious, do you know any replacements for this lib? Any ideas how to implement it from the scratch?

推荐答案

由于v22.2.0,Android的支持团队包括了一个 ItemTouchHelper 类,使刷卡到-dismiss并拖动和拖放pretty的简单。这可能不是作为全功能的,因为一些图书馆在那里,但它是直接从Android团队。

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.

    +的RecyclerView库
  • 更​​新您的build.gradle进口v22.2。

  • Update your build.gradle to import v22.2.+ of the RecyclerView library

compile 'com.android.support:recyclerview-v7:22.2.+'

  • 实例化一个合适的SimpleCallback的ItemTouchHelper

  • Instantiate an ItemTouchHelper with an appropriate SimpleCallback

    ItemTouchHelper.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需要在要启用拖和下降的方向,并且要启用刷卡方向。

    ** Note that the SimpleCallback takes in the directions that you want to enable drag-and-drop and the directions that you want to enable swiping.

    附加到您的RecyclerView

    Attach to your RecyclerView

    itemTouchHelper.attachToRecyclerView(recyclerView);
    

  • 这篇关于轻扫解雇的RecyclerView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆