该控件的优势:android
Step 1. Add it in your root build.gradle at the end of repositories: allprojects { repositories { ... maven { url 'https://jitpack.io' } } } Step 2. Add the dependency dependencies { implementation 'com.github.WelliJohn:ASwipeLayout:0.0.2' }
<?xml version="1.0" encoding="utf-8"?> <wellijohn.org.swipevg.ASwipeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal"> <LinearLayout android:id="@+id/ll_content" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="#FFFFFF" android:orientation="horizontal"> //在这里是实现你的主item的东西,根据大家的项目随便添加 </LinearLayout> <LinearLayout android:id="@+id/right_menu_content" android:layout_width="wrap_content" android:layout_height="match_parent"> //在这里是实现右侧的菜单,根据大家的项目随便添加 </LinearLayout> </wellijohn.org.swipevg.SwipeLayout>
注意在这里ll_content,right_menu_content是必定要的,这个id对应的布局不要本身去改变,之后有须要会放开,目前的话,通常的状况大家只须要定制主item的内容和右侧菜单栏了,在这里我也省去了定义一些额外的自定义view了,单纯就是用id,来区分主item和右侧的菜单。git
由于item复用会使得当咱们滑出某个menu的时候,再进行RecyclerView的上下滑动时,会使得其余的Item也滑出了menu,这就是item复用致使了布局错乱,因此针对这类型的问题的话,我在这里已经提供了OnSwipeStateChangeListener接口,在这里大家能够记录下滑动的状态,在onBindViewHolder方法里面,根据状态来设定Item是打开menu仍是关闭menu:github
@Override public void onBindViewHolder(ViewHolder holder, int position) { final Person person = mDatas.get(position); holder.scrollDelLl.setOpen(person.isOpen()); holder.scrollDelLl.setOnSwipeStateChangeListener(new OnSwipeStateChangeListener() { @Override public void onSwipeStateChange(boolean open) { person.setOpen(open); } }); }
如上代码就能够解决Item复用致使布局错乱的问题了(粑粑不再用担忧RecyclerView复用的问题了)。app