Android仿QQ列表滑动
VastSwipeListView
一款支持自定义的仿QQ列表滑动控件
? 特性
- ? 支持自定义菜单项,包括
标题图标菜单背景色标题字体大小图标大小 - ? 支持自定义菜单类别,包括
只有左菜单只有右菜单左右都有菜单 - ? 支持自定义菜单打开和关闭时间
- ? 支持自定义菜单
Interpolator - ? 提供初始值以便具有更好的兼容性
- ? 分离式设计,使用
VastSwipeMenuMgr进行样式管理 - ? 使用菜单项去定义菜单点击事件,避免接口化设计导致你需要重复书写if判断
? 快速开始
-
在你的布局中添加
VastSwipeListView<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".SlideActivity"> <com.gcode.vastswipelayout.view.VastSwipeListView android:id="@+id/listview" android:layout_width="match_parent" android:layout_height="match_parent" android:choiceMode="singleChoice"/> </LinearLayout> -
使用
VastSwipeMenuItem来定义你的菜单项,调用VastSwipeMenuMgr内的方法将菜单项添加进去我们这里以定义撤销项举例
val deleteItem = VastSwipeMenuItem(this@SlideActivity) deleteItem.setBackgroundByColorInt(0xFF1e90ff) deleteItem.setTitleByString("撤销") deleteItem.setTitleColorByColorInt(Color.WHITE) deleteItem.setIconByResId(R.drawable.ic_delete) deleteItem.setClickEvent { item: VastSwipeMenuItem, position: Int -> run { Toast.makeText(this@SlideActivity, "${item.title} $position", Toast.LENGTH_SHORT) .show() } } swipeMenuMgr.addLeftMenuItem(deleteItem) -
准备列表项数据的adapter
val listViewAdapter = ListViewAdapter(this, R.layout.listview_item, lists) -
将设置好的
VastSwipeMenuMgr和列表项Adapter传给VastSwipeListViewvastSwipeListView.setSwipeMenuMgr(swipeMenuMgr) vastSwipeListView.adapter = listViewAdapter vastSwipeListView.onItemClickListener = AdapterView.OnItemClickListener { _, _, arg2, _ -> Toast.makeText( context, "位置 " + arg2 + " >>> value:" + lists[arg2], Toast.LENGTH_SHORT ).show() }