android侧滑删除框架,Android 侧滑菜单(侧滑删除)总结

基本实现思路

通过自定义View的方式实现步骤:

1、自定义ViewGroup

2、在onLayout 中,获取childView并对他们进行布局,这一步比较重要,content 占满屏幕,菜单View 在屏幕之外,当滑动的时候,content滑屏幕,menu 进入屏幕,就达到了我需要的效果,布局草图如下:

6aa308996238

image

3、重写dispatchTouchEvent和onInterceptTouchEvent方法拦截事件和处理滚动。滑动效果的实现既可以用Scroller,也可以用属性动画ValueAnimator。

添加依赖

//侧滑SwipeRecyclerView

implementation 'com.yanzhenjie:recyclerview-swipe:1.1.4'

1、SwipeRevealLayout

SwipeRevealLayout 使用简单、代码入侵低,不但支持左右侧滑菜单,还支持上下滑出菜单。可以配合各种布局使用,包括RecyclerView 、ListView、ScrollView 等,效果很赞

使用方式:

android:layout_width="match_parent"

android:layout_height="match_parent"

app:mode="same_level"

app:dragEdge="left">

android:layout_width="wrap_content"

android:layout_height="match_parent" />

android:layout_width="match_parent"

android:layout_height="match_parent" />

在adapterclass 中:

public class Adapter extends RecyclerView.Adapter {

// This object helps you save/restore the open/close state of each view

private final ViewBinderHelper viewBinderHelper = new ViewBinderHelper();

public Adapter() {

// uncomment the line below if you want to open only one row at a time

// viewBinderHelper.setOpenOnlyOne(true);

}

@Override

public void onBindViewHolder(ViewHolder holder, int position) {

// get your data object first.

YourDataObject dataObject = mDataSet.get(position);

// Save/restore the open/close state.

// You need to provide a String id which uniquely defines the data object.

viewBinderHelper.bind(holder.swipeRevealLayout, dataObjec

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值