Giter Site home page Giter Site logo

topjohn / swiperecyclerview Goto Github PK

View Code? Open in Web Editor NEW

This project forked from yanzhenjie/swiperecyclerview

0.0 3.0 0.0 10.05 MB

最强RecyclerView,Item侧滑菜单,长按拖拽Item,滑动删除Item。可以和任何下拉刷新框架结合使用。

Home Page: http://blog.csdn.net/yanzhenjie1003/article/details/52115566

Java 100.00%

swiperecyclerview's Introduction

SwipeRecyclerView

严振杰的主页:http://www.yanzhenjie.com
严振杰的博客:http://blog.csdn.net/yanzhenjie1003
技术交流群:547839514,加群前请务必阅读群行为规范


演示Demo apk下载

引用方法

  • Eclipse 请自行下载源码
  • AndroidStudio使用Gradle构建添加依赖(推荐)
compile 'com.yanzhenjie:recyclerview-swipe:1.0.0'

本库引用的RecyclerView版本如下:

compile 'com.android.support:recyclerview-v7:23.4.0'

效果图

gif有一些失真,且网页加载速度慢,可以下载demo的apk看效果。

侧滑菜单

拖拽、侧滑菜单

拖拽、侧滑删除

使用介绍

这里列出关键实现,具体请参考demo,或者加最上面的交流群一起讨论。 更多教程请进入我的博客查看。

启用SwipeReyclerView的长按Item拖拽功能和侧滑删除功能

recyclerView.setLongPressDragEnabled(true);// 开启长按拖拽
recyclerView.setItemViewSwipeEnabled(true);// 开启滑动删除。
recyclerView.setOnItemMoveListener(onItemMoveListener);// 监听拖拽和侧滑删除,更新UI。

添加Item侧滑菜单

侧滑菜单支持自动打开某个Item的菜单,并可以指定是左边还是右边的:

// 打开第一个Item的左侧菜单。
recyclerView.openLeftMenu(0);

// 打开第一个Item的右侧菜单。
recyclerView.openRightMenu(0);
  • 第一步,引用自定义View:SwipeMenuReyclerView:
<com.yanzhenjie.recyclerview.swipe.SwipeMenuRecyclerView
    android:id="@+id/recycler_view"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:layout_behavior="@string/appbar_scrolling_view_behavior" />
  • 第二步,设置菜单创建器、菜单点击监听:
SwipeMenuRecyclerView swipeMenuRecyclerView = findViewById(R.id.recycler_view);
// 设置菜单创建器。
swipeMenuRecyclerView.setSwipeMenuCreator(swipeMenuCreator);
// 设置菜单Item点击监听。
swipeMenuRecyclerView.setSwipeMenuItemClickListener(menuItemClickListener);
  • 第三步,菜单创建器创建菜单:
/**
 * 菜单创建器。在Item要创建菜单的时候调用。
 */
private SwipeMenuCreator swipeMenuCreator = new SwipeMenuCreator() {
    @Override
    public void onCreateMenu(SwipeMenu swipeLeftMenu, SwipeMenu swipeRightMenu, int viewType) {

        SwipeMenuItem addItem = new SwipeMenuItem(mContext)
            .setBackgroundDrawable(R.drawable.selector_green)// 点击的背景。
            .setImage(R.mipmap.ic_action_add) // 图标。
            .setWidth(size) // 宽度。
            .setHeight(size); // 高度。
        swipeLeftMenu.addMenuItem(addItem); // 添加一个按钮到左侧菜单。

        SwipeMenuItem deleteItem = new SwipeMenuItem(mContext)
            .setBackgroundDrawable(R.drawable.selector_red)
            .setImage(R.mipmap.ic_action_delete) // 图标。
            .setText("删除") // 文字。
            .setTextColor(Color.WHITE) // 文字颜色。
            .setTextSize(16) // 文字大小。
            .setWidth(size)
            .setHeight(size);
        swipeRightMenu.addMenuItem(deleteItem);// 添加一个按钮到右侧侧菜单。
    }
};
  • 第四步,继承SwipeMenuAdapter,和正常的Adapter一样使用:
public class MenuAdapter extends SwipeMenuAdapter<MenuAdapter.DefaultViewHolder> {

    @Override
    public int getItemCount() {
        return 0;
    }

    @Override
    public View onCreateContentView(ViewGroup parent, int viewType) {
        return null;
    }

    @Override
    public ViewHolder onCompatCreateViewHolder(View realContentView, int viewType) {
        return null;
    }

    @Override
    public void onBindViewHolder(MenuAdapter.DefaultViewHolder holder, int position) {
    }
}

#License

Copyright 2016 Yan Zhenjie

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

swiperecyclerview's People

Watchers

James Cloos avatar Top John avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.