android侧滑删除框架,Android 侧滑菜单(侧滑删除)总结
基本实现思路
通过自定义View的方式实现步骤:
1、自定义ViewGroup
2、在onLayout 中,获取childView并对他们进行布局,这一步比较重要,content 占满屏幕,菜单View 在屏幕之外,当滑动的时候,content滑屏幕,menu 进入屏幕,就达到了我需要的效果,布局草图如下:
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, dataObject.getId());
// do your regular binding stuff here
}
}
private class ViewHolder extends RecyclerView.ViewHolder {
private SwipeRevealLayout swipeLayout;
private View frontLayout;
private View deleteLayout;
private TextView textView;
public ViewHolder(View itemView) {
super(itemView);
swipeLayout = (SwipeRevealLayout) itemView.findViewById(R.id.swipe_layout);
frontLayout = itemView.findViewById(R.id.front_layout);
deleteLayout = itemView.findViewById(R.id.delete_layout);
textView = (TextView) itemView.findViewById(R.id.text);
}
public void bind(final String data) {
deleteLayout.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mDataSet.remove(getAdapterPosition());
notifyItemRemoved(getAdapterPosition());
}
});
textView.setText(data);
frontLayout.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
String displayText = "" + data + " clicked";
Toast.makeText(mContext, displayText, Toast.LENGTH_SHORT).show();
Log.d("RecyclerAdapter", displayText);
}
});
}
}
效果图:
image
image
image
2、SwipeDelMenuLayout
和SwipeRevealLayout差不多。
使用方式:
在RecyclerView、ListView 可直接使用,在Adapter 中,在item布局最外层包上
SwipeMenuLayout就好。
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="100dp"
android:clickable="true"
android:paddingBottom="1dp">
android:id="@+id/content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="?android:attr/selectableItemBackground"
android:gravity="center"
android:text="项目中我是任意复杂的原ContentItem布局"/>
android:id="@+id/btnTop"
android:layout_width="60dp"
android:layout_height="match_parent"
android:background="#d9dee4"
android:text="置顶"
android:textColor="@android:color/white"/>
android:id="@+id/btnUnRead"
android:layout_width="120dp"
android:layout_height="match_parent"
android:background="#ecd50a"
android:clickable="true"
android:text="标记未读"
android:textColor="@android:color/white"/>
android:id="@+id/btnDelete"
android:layout_width="60dp"
android:layout_height="match_parent"
android:background="@color/red_ff4a57"
android:text="删除"
android:textColor="@android:color/white"/>
效果图:
image
image
3、AndroidSwipeLayout
出自代码家大神,功能强大,支持上下左右四个方向滑出菜单,可单独使用,也支持RecyclerView 和 ListView等列表,Adapter需要继承RecylerViewAdapter或者BaseSwipeAdapter。
使用:
android:layout_width="match_parent" android:layout_height="80dp">
android:background="#66ddff00"
android:id="@+id/bottom_wrapper"
android:layout_width="160dp"
android:weightSum="1"
android:layout_height="match_parent">
android:padding="10dp"
android:background="#ffffff"
android:layout_width="match_parent"
android:layout_height="match_parent">
代码中:
SwipeLayout swipeLayout = (SwipeLayout)findViewById(R.id.sample1);
//set show mode.
swipeLayout.setShowMode(SwipeLayout.ShowMode.LayDown);
//add drag edge.(If the BottomView has 'layout_gravity' attribute, this line is unnecessary)
swipeLayout.addDrag(SwipeLayout.DragEdge.Left, findViewById(R.id.bottom_wrapper));
swipeLayout.addSwipeListener(new SwipeLayout.SwipeListener() {
@Override
public void onClose(SwipeLayout layout) {
//when the SurfaceView totally cover the BottomView.
}
@Override
public void onUpdate(SwipeLayout layout, int leftOffset, int topOffset) {
//you are swiping.
}
@Override
public void onStartOpen(SwipeLayout layout) {
}
@Override
public void onOpen(SwipeLayout layout) {
//when the BottomView totally show.
}
@Override
public void onStartClose(SwipeLayout layout) {
}
@Override
public void onHandRelease(SwipeLayout layout, float xvel, float yvel) {
//when user's hand released.
}
});
配合RecyclerView 和ListView 等列表的使用,请看github给出的 Samples
效果图:
image
4、SwipeRecyclerView
本库的一大特色是它滑出的菜单可以是左右排列的,也可以是上下排列,提供多种选择,不过侵入性稍微有点高,需要使用本库提供的SwipeRecyclerView,但是使用方式与提供的api和原生的RecyclerView是一样的。还有它通过代码来创建划出的菜单。如下:
// 设置监听器。
swipeRecyclerView.setSwipeMenuCreator(mSwipeMenuCreator);
// 创建菜单:
SwipeMenuCreator mSwipeMenuCreator = new SwipeMenuCreator() {
@Override
public void onCreateMenu(SwipeMenu leftMenu, SwipeMenu rightMenu, int position) {
SwipeMenuItem deleteItem = new SwipeMenuItem(mContext)
...; // 各种文字和图标属性设置。
leftMenu.addMenuItem(deleteItem); // 在Item左侧添加一个菜单。
SwipeMenuItem deleteItem = new SwipeMenuItem(mContext)
...; // 各种文字和图标属性设置。
leftMenu.addMenuItem(deleteItem); // 在Item右侧添加一个菜单。
// 注意:哪边不想要菜单,那么不要添加即可。
}
};
// 菜单点击监听。
swipeRecyclerView.setOnItemMenuClickListener(mItemMenuClickListener);
OnItemMenuClickListener mItemMenuClickListener = new OnItemMenuClickListener() {
@Override
public void onItemClick(SwipeMenuBridge menuBridge, int position) {
// 任何操作必须先关闭菜单,否则可能出现Item菜单打开状态错乱。
menuBridge.closeMenu();
// 左侧还是右侧菜单:
int direction = menuBridge.getDirection();
// 菜单在Item中的Position:
int menuPosition = menuBridge.getPosition();
}
};
效果图:
image
image
image
5、RecyclerViewUndoSwipe
一个可以拖拽和侧滑的UI效果,动画非常炫。
效果图:
image
它没有封装成库,是一个效果demo,具体使用方式和实现,可以去看源码
android侧滑删除框架,Android 侧滑菜单(侧滑删除)总结相关推荐
- android 观察者的框架,Android 架构师7 设计模式之观察者模式
前言 当对象间存在一对多关系时,则使用观察者模式(Observer Pattern).比如,当一个对象被修改时,则会自动通知它的依赖对象.观察者模式属于行为型模式. 观察者模式.png 观察者模式 被 ...
- android banner动画框架,Android Studio Banner轮播图使用
现在恰好有个项目需要做个轮播图效果,这个需求也是很常见的需求,于是就做个笔记写一下实现过程 分为加载本地图片和网络图片 加载本地图片 第一步:先在build.gradle中加入banner和glide ...
- Android测试最新框架,Android单元测试-常见的方案比较
前言 本文将介绍在Android Studio中,android单元测试的介绍和实现.相关代码托管在github上的AndroidJunitDemo中,涉及到的用例代码收集于google官方提供的测试 ...
- Android PDF阅读框架/Android PDF框架简单使用,简单快速集成简易的PDF阅读器 ,AndroidPdfViewer框架简单使用。
文章目录 1:前言 使用步骤 步骤1 导包 / 导引用 / 添加依赖 步骤2 更改xml布局文件 步骤3 java文件处理 1:前言 因为前段时间项目展示,我们小组本打算做的是TXT阅读框架,但是找了 ...
- android 屏幕适配框架,Android屏幕适配
为什么要进行Android屏幕适配 由于Android系统的开放性,任何用户.开发者.OEM厂商.运营商都可以对Android进行定制,于是导致: 1.Android系统碎片化:小米定制的MIUI.魅 ...
- android媒体播放框架,Android 使用超简单的多媒体播放器JiaoZiVideoPlayer
在之前的项目中用到了视频播放的功能,在网上看了看使用了大家用的比较多的一个开源项目JiaoZiVideo可以迅速的实现视频播放的相关功能. JiaoZiVideo的简单使用 集成了JiaoZiVide ...
- android使用 注解框架,Android实践 | 注解框架ButterKnife基本使用
使用ButterKnife,我们可以不用写很多的findViewById()语句,以及通过getResources获取String.Color等资源,这可以让我们的代码更加简洁,使用起来也很方便.下面 ...
- android svg动画框架,Android实现炫酷SVG动画效果
svg是目前十分流行的图像文件格式了,svg严格来说应该是一种开放标准的矢量图形语言,使用svg格式我们可以直接用代码来描绘图像,可以用任何文字处理工具打开svg图像,通过改变部分代码来使图像具有交互 ...
- android的自动布局框架,Android ConstraintLayout 构建自适应界面
使用 ConstraintLayout 构建自适应界面 ConstraintLayout 可让您使用扁平视图层次结构(无嵌套视图组)创建复杂的大型布局.它与 RelativeLayout 相似,其中所 ...
- android http最新框架,Android框架学习笔记02AndroidAsycHttp框架
上一篇中我们介绍了OkHttp3.0框架的基本使用方法,这一篇我们学习一下Android的另外一个网络请求框架--AsyncHttpClient框架.Asynchttpclient框架是一个开源的异步 ...
最新文章
- 【springboot】配置
- CTFshow 信息收集 web17
- OSError: Cannot initialize new instance of inotify, Errno=Too many open files (EMFILE) 问题解决
- Kooboo 全文索引研究
- 装X神器!NuShell
- FreeRTOS队列
- 【转载保存】cookie在登录时的使用
- html5做咖啡网页素材,HTML5/CSS3咖啡品类切换动画
- php codeigniter 语言,关于php:CodeIgniter:语言文件编辑器?
- Mosquitto安装及使用简介
- 利用Python Matplotlib库做简单的视觉化
- AgreementMaker:Efficient Matching for Large Real-World 翻译
- python快捷键设置,环境设置、输出print、转义字符、标识符
- matlab画图不想显示x轴数据,Matlab - 情节; 修改X轴值而不修改图形
- 75岁老人用excel表格画画,令人叹服!
- 单机斗地主之完整功能初版
- FPGA实现的SPI协议(二)----基于SPI接口的FLASH芯片M25P16的使用
- tomcat--catalina
- ghost系统安装无法启动服务器,手把手教你重装Ghost系统错误怎么办
- 北航计算机学院本科优秀毕业论文,我校荣获32项北京市普通高等学校优秀本科生毕业设计(论文)...
热门文章
- python0.1+0.2不等于0.3_为什么0.1+0.2不等于0.3
- UE4联机多人游戏基本设置
- Qt -qss样式表
- 数据存储---内存列式数据库KDB+(Q)文档
- 混沌之初--制作一款RPG游戏
- 播布客教学视频_C学习笔记_9.1_整形转字符串
- 【周六福利来了~】优才安卓公开课:程序员到架构师之路
- Linux Ubuntu系统fwknop单包授权认证(SPA)流程
- oracle占位符怎么打,oracle所支持的占位符是什么
- 优质的服务器机房有哪些表现