手机
当前位置:查字典教程网 >编程开发 >安卓软件开发 >详解SwipeListView框架实现微信QQ滑动删除效果
详解SwipeListView框架实现微信QQ滑动删除效果
摘要:QQ或者微信出现过滑动,最近联系人列表,可以删去当前选中的联系人,这个功能很棒。就是试着做了下。其实是使用了开源框架SwipeListVie...

QQ或者微信出现过滑动,最近联系人列表,可以删去当前选中的联系人,这个功能很棒。

就是试着做了下。其实是使用了开源框架SwipeListView 。

详解SwipeListView框架实现微信QQ滑动删除效果1

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; }

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持查字典教程网。

【详解SwipeListView框架实现微信QQ滑动删除效果】相关文章:

android panellistview 圆角实现代码

ListView 分页加载更新实例分享

android表格效果之ListView隔行变色实现代码

解析在Android中为TextView增加自定义HTML标签的实现方法

在Android中动态添加Panel框架的实现代码

android二级listview列表实现代码

Android在listview添加checkbox实现原理与代码

Android 用SQLite实现事务的方法

android中实现指针滑动的动态效果方法

android webview 简单浏览器实现代码

精品推荐
分类导航