使用开源SwipeRevealLayout,来对item进行右侧滑动删除

先上图看效果
https://github.com/chthai64/SwipeRevealLayout

github地址: https://github.com/chthai64/SwipeRevealLayout

这是简单做了一个item右侧滑动删除演示,还有其他类似,可以前往github查看

studio中的build.gradle文件中添加依赖

dependencies {
    compile 'com.chauthai.swipereveallayout:swipe-reveal-layout:1.4.1'
}

Layout 文件



        
        

        
        
            

我的 layout 文件




    

        

            

                


            

        
    

    

        

            

                

                    

                    

                    

                        

                        

                    

                

                

                    

                    

                    

                        

                        

                    

                

                

                    

                    

                        

                        

                    
                
            
        
    

看布局,外面用到的SwipeRevealLayout包裹完,前面FrameLayout是滑动删除,后面FrameLayout是正常的item

我的Activity代码

        List two_task_list = new ArrayList<>();
        for (int i = 0; i < 6; i++) {
            two_task_list.add("虫子" + i);
        }
        TwoTaskDetailsAdapter twoTaskDetailsAdapter = new TwoTaskDetailsAdapter(R.layout.item_two_water_task_details,two_task_list);

        RecyclerView rv_two_task = helper.getView(R.id.rv_two_task);

        GridLayoutManager layoutManager = new GridLayoutManager(mContext, 1);
        rv_two_task.setLayoutManager(layoutManager);
        rv_two_task.setAdapter(twoTaskDetailsAdapter);

我的Adapter代码

public class TwoTaskDetailsAdapter extends BaseQuickAdapter {

    public TwoTaskDetailsAdapter(int layoutResId, @Nullable List data) {
        super(layoutResId, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, String item) {
        LinearLayout ll_item_delete = (LinearLayout) helper.getView(R.id.ll_item_delete);
        ll_item_delete.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ToastUtil.s("删除:"+item);
            }
        });
    }

}

至此就大功告成了,赶紧去试试吧~铁子

你可能感兴趣的:(使用开源SwipeRevealLayout,来对item进行右侧滑动删除)