QQ或者微信出现过滑动,最近联系人列表,可以删去当前选中的联系人,这个功能很棒。
就是试着做了下。其实是使用了开源框架SwipeListVIEw 。
SwipeListVIEw 与一般的ListVIEw使用方式差不多,只是增加了一些特殊功能。
<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 -ListVIEw Item正常显示的控件ID,且必须与Item的布局文件中的控件ID一样
•swipeBackVIEw - 手指滑动时显示的,隐藏在FrontVIEw后面,且必须与item的布局文件中控件ID一样
•swipeActionleft - 左滑的动作,默认reveal,即显示BackVIEw,还有dismiss,choice会触发响应的方法。
•swipeActionRight - 右滑动作,其他同上
•swipeMode - Default: 'both' 设置左滑、右滑、都支持
•swipeCloseAllitemsWhenMoveList - 当滚动ListvIEw时,关闭所有展开的Item,最好不要设置为false,由于item的
• 复用,false存在一些问题。
•swipeOpenOnLongPress - Default: 'true' 长按时触发显示
•swipeAnimationTime - 动画时间长度
•swipeOffsetleft - left offset 左偏移量
•swipeOffsetRight - right offset 右偏移量
mSwipeListVIEw = (SwipeListVIEw) findVIEwByID(R.ID.ID_swipeListvIEw); mAdapter = new DataAdapter(this,mDatas,mSwipeListVIEw); mSwipeListVIEw.setAdapter(mAdapter); mSwipeListVIEw.setSwipeListVIEwListener(new BaseSwipeListVIEwListener() { @OverrIDe //重写BaseSwipeListVIEwListener父类需要的方法 };
使用方式很简单 和普通的ListVIEw 相似,不需要多说。
对于 ListVIEw的Item删除单个元素,只需要在Adapter中处理button的点击事件,或者写一个回调传回Activity中处理
我这里给出在Adapter中处理的方式的代码:
@OverrIDe public VIEw getVIEw(final int position,VIEw convertVIEw,VIEwGroup parent) { convertVIEw = mInflater.inflate(R.layout.List_item,null); TextVIEw tv = (TextVIEw) convertVIEw.findVIEwByID(R.ID.ID_text); button del = (button) convertVIEw.findVIEwByID(R.ID.ID_remove); tv.setText(mDatas.get(position)); del.setonClickListener(new OnClickListener() { @OverrIDe public voID onClick(VIEw v) { mDatas.remove(position); notifyDataSetChanged(); /** * 关闭SwipeListVIEw * 不关闭的话,刚删除位置的item存在问题 * 在监听事件中onListChange中关闭,会出现问题 */ mSwipeListVIEw.cloSEOpenedItems(); } }); return convertVIEw; }
源码下载:https://github.com/honjane/SwipeListViewDemo
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持编程小技巧。
总结以上是内存溢出为你收集整理的详解SwipeListView框架实现微信\QQ滑动删除效果全部内容,希望文章能够帮你解决详解SwipeListView框架实现微信\QQ滑动删除效果所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)