SwipeListView是Github上的一个开源框架,地址:https://github.com/47deg/android-swipelistview

  SwipeListView was born out of the need to add swipe gestures to ListView on Android.

  因为开发需要整一个类似QQ侧滑删除的ListView,一开始准备自己写一个自定义layout作为item布局,依稀记得有个叫swipelistview的开源框架,结果还真可以拿来用,效果略有差别,但也满足项目要求了。那么,问题也来了,Github上最后的push的SwipelistView使用的是Gradle来构建,无奈鄙人几个月来一直在用es开始开发,考虑到可能要查看或者修改它的源码,就只好手工转为ecplise下的工程。下面先上Demo说明基本使用方法,方法都很简单,主要是网上搜索的资料都不是很完整,自己写一篇备忘,也供新手朋友们参考,再说说Gradle构建的swipelistview Module如何导入eclipse工程。

  一、引用swipelistview库开发带侧滑+按钮的ListView

    swipelistview的使用同listview的使用方法差不多,因为swipelistview是直接继承于ListView的,只是扩展了一些方法。

    官方给出了再XML布局文件中的基本写法:

 <com.fortysevendeg.swipelistview.SwipeListView
xmlns:swipe="http://schemas.android.com/apk/res-auto"
android:id="@+id/example_lv_list"
android:listSelector="#00000000"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
swipe:swipeFrontView="@+id/front"
swipe:swipeBackView="@+id/back"
swipe:swipeActionLeft="[reveal | dismiss]"
swipe:swipeActionRight="[reveal | dismiss]"
swipe:swipeMode="[none | both | right | left]"
swipe:swipeCloseAllItemsWhenMoveList="[true | false]"
swipe:swipeOpenOnLongPress="[true | false]"
swipe:swipeAnimationTime="[miliseconds]"
swipe:swipeOffsetLeft="[dimension]"
swipe:swipeOffsetRight="[dimension]"
/>

各属性说明如下:

swipeFrontView - Required - front view id.
swipeBackView - Required - back view id.
swipeActionLeft - Optional - left swipe action Default: 'reveal'
swipeActionRight - Optional - right swipe action Default: 'reveal'
swipeMode - Gestures to enable or 'none'. Default: 'both'
swipeCloseAllItemsWhenMoveList - Close revealed items on list motion. Default: 'true'
swipeOpenOnLongPress - Reveal on long press Default: 'true'
swipeAnimationTime - item drop animation time. Default: android configuration
swipeOffsetLeft - left offset
swipeOffsetRight - right offset

Demo地址,效果图:

我们自己定义swipelistview的item布局:

 <?xml version="1.0" encoding="utf-8"?>

 <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" > <LinearLayout
android:id="@+id/backview"
android:layout_width="match_parent"
android:layout_height="70dp"
android:background="#eee"
android:tag="back" > <Button
android:id="@+id/example_1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="2"
android:background="@null" /> <Button
android:id="@+id/edit"
android:layout_width="0dp"
android:layout_height="60dp"
android:layout_gravity="center"
android:layout_weight="1"
android:background="@drawable/edit"
android:text="编辑" /> <Button
android:id="@+id/del"
android:layout_width="0dp"
android:layout_height="60dp"
android:layout_gravity="center"
android:layout_marginLeft="10dp"
android:layout_weight="1"
android:background="@drawable/del"
android:text="删除" />
</LinearLayout> <RelativeLayout
android:id="@+id/frontview"
android:layout_width="match_parent"
android:layout_height="70dp"
android:background="#ffffff"
android:orientation="vertical"
android:tag="front" > <TextView
android:id="@+id/example_row_tv_title"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:textSize="16sp" />
</RelativeLayout> </FrameLayout>

在布局swipeview所在布局文件中的定义

 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:swipe="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" > <com.fortysevendeg.swipelistview.SwipeListView
android:id="@+id/example_lv_list"
android:layout_width="match_parent"
android:layout_height="match_parent"
swipe:swipeActionLeft="reveal"
swipe:swipeActionRight="reveal"
swipe:swipeAnimationTime="0"
swipe:swipeBackView="@+id/backview"
swipe:swipeCloseAllItemsWhenMoveList="true"
swipe:swipeFrontView="@+id/frontview"
swipe:swipeMode="both"
swipe:swipeOffsetLeft="0dp"
swipe:swipeOffsetRight="0dp"
swipe:swipeOpenOnLongPress="false" /> </RelativeLayout>

  使用注意点:

     为了让每次显示滑动一条数据,需要在你自己实现的BaseSwipeListViewListener中重写onStartOpen方法,在里面调用mSwipeListView.closeOpenedItems()。

  二、导入swipelistview到eclipse工程

    也许有人一看是gradle构建的android项目就不知道怎么办了,以为as构建的项目是不能之间导入eclipse工程的。幸运的是,swipelistview工程极其简洁,手工导入eclipse也是比较的容易的。

    1. 新建一个android工程,勾选标记为libraray,且不用创建activity。

      

    2. 将下载下来的android-swipelistview-master工程中\android-swipelistview-master\swipelistview\src\main\java下的com文件下直接粘贴到新建工程的src目录下。

同时把\android-swipelistview-master\swipelistview\src\main目录下的res资源放到eclipse下新建的Android库工程对应目录下。

    3. 做完上面两部还没有完,因为swipelistview依赖nineoldandroids库,且目前的swipelistview版本依赖nineoldandroids-2.4.0+,下载地址https://github.com/JakeWharton/NineOldAndroids,可以只下载

nineoldandroids-2.4.0.jar,直接放在新建android库工程的libs目录下即可。至此导入工作完成。

Android开源框架之SwipeListView导入及模拟QQ侧滑的更多相关文章

  1. Android进阶笔记13:RoboBinding(实现了数据绑定 Presentation Model(MVVM) 模式的Android开源框架)

    1.RoboBinding RoboBinding是一个实现了数据绑定 Presentation Model(MVVM) 模式的Android开源框架.从简单的角度看,他移除了如addXXListen ...

  2. [转]Android开源框架ImageLoader的完美例子

    Android开源框架ImageLoader的完美例子 2013年8月19日开源框架之Universal_Image_Loader学习 很多人都在讨论如何让图片能在异步加载更加流畅,可以显示大量图片, ...

  3. Android开源框架ViewPageIndicator和ViewPager实现Tab导航

    前言: 关于使用ViewPageIndicator和ViewPager实现Tab导航,在开发社区里已经有一堆的博客对其进行了介绍,假设我还在这里写怎样去实现.那简直就是老生常谈,毫无新奇感,并且.我也 ...

  4. Android 开源框架Universal-Image-Loader学习

    Android 开源框架Universal-Image-Loader完全解析(一)--- 基本介绍及使用 Android 开源框架Universal-Image-Loader完全解析(二)--- 图片 ...

  5. Android 开源框架Universal-Image-Loader完全解析(三)---源代码解读

    转载请注明本文出自xiaanming的博客(http://blog.csdn.net/xiaanming/article/details/39057201),请尊重他人的辛勤劳动成果,谢谢! 本篇文章 ...

  6. Android 开源框架Universal-Image-Loader完全解析(二)--- 图片缓存策略详解

    转载请注明本文出自xiaanming的博客(http://blog.csdn.net/xiaanming/article/details/26810303),请尊重他人的辛勤劳动成果,谢谢! 本篇文章 ...

  7. android 开源框架推荐

    同事整理的 android 开源框架,个个都堪称经典.32 个赞! 1.volley 项目地址 https://github.com/smanikandan14/Volley-demo (1)  JS ...

  8. Android 开源框架Universal-Image-Loader全然解析(二)--- 图片缓存策略具体解释

    转载请注明本文出自xiaanming的博客(http://blog.csdn.net/xiaanming/article/details/26810303),请尊重他人的辛勤劳动成果,谢谢! 本篇文章 ...

  9. Android开源框架Afinal第一篇——揭开圣女的面纱

    Android开源框架Afinal第一篇——揭开圣女的面纱 分类: Android开源框架哪点事2013-09-02 14:25 260人阅读 评论(0) 收藏 举报 Afinal 这是Afinal在 ...

随机推荐

  1. DataTables DOM定位

    datatables默认会打开部分特性,比如搜索框,分页显示等等,或许你不喜欢datatables这样去布局,可能你想把分页按钮放在底部的中间,搜索框放在顶部的左上角,不用担心datatables考虑 ...

  2. 在预装win8的电脑上换win7系统讲解

    现在买电脑,如果电脑预装的系统是win8系统,那么这个电脑的默认启动模式应该就是UEFI模式,现在UEFI模式正在逐渐取代传统模式.UEFI启动需要一个独立的分区,它将系统启动文件和操作系统本身隔离, ...

  3. 关于mobiscroll插件的使用

    在网上找了很多资料,各大猿友对这个插件都做了很详细的介绍,我也是看了很多资料才发现原来这个插件有一些需要注意的地方,在这总结了一下: //时间 var currYear = (new Date()). ...

  4. Retrofit2.0+OkHttp打印Request URL(请求地址参数)

    学习了Retrofit中的拦截器功能:实现日志中打印请求头内容 Retrofit 2+ 是基于OKHttp进行封装的,那么也就是说想进行请求拦截然后进行打印出来的话,就必须要从OkHttp进行入手. ...

  5. XCode中使用SVN 教程

    修改subversion.config方法: 可以直接在终端上输入:vi ~/.subversion/config来编辑. 也可以通过Finder搜索.subversion,点击下边的+号,进入高级搜 ...

  6. Matlab 图像预处理

    %%%%%%%%%%%%%%%%% %%降采样 clear all im={}; %创建字典保存读取的图片 dis=dir('F:\kaggle_data_zip\Sample\*.jpeg');%% ...

  7. Linux方面收藏的一点儿资料

    初来乍到,也算是第一次写技术类相关的博客,就分享几篇收藏的Linux相关的资料吧,希望可以给需要的人一点帮助. 1.<高级Bash脚本编程指南>:该网站详细讲解了Bash Shell编程的 ...

  8. Codeforces 479E Riding in a Lift

    http://codeforces.com/problemset/problem/432/D 题目大意: 给出一栋n层的楼,初始在a层,b层不能去,每次走的距离必须小于当前位置到b的距离,问用电梯来回 ...

  9. PyCharm常用设置

    pycharm,优秀的python开发工具 本文介绍一点python开发工具,pycharm的使用方式. 内容仅仅为最常用的几点,想要了解更多,请自行谷歌. 1.常用工具栏 唤出常用工具栏,View ...

  10. linux系统下怎么安装.deb文件?

    linux系统下怎么安装.deb文件? deb 是 ubuntu .debian 的格式. rpm 是 redhat .fedora .suse 的格式. 他们不通用(尽管能够转换一下). deb是d ...