这里有新鲜出炉的 Javascript 教程,程序狗速度看过来!
Javascript 是一种由 Netscape 的 LiveScript 发展而来的原型化继承的基于对象的动态类型的区分大小写的客户端脚本语言,主要目的是为了解决服务器端语言,比如 Perl,遗留的速度问题,为客户提供更流畅的浏览效果。
这篇文章主要为大家详细介绍了 SwipeListView 框架实现微信 \ QQ 滑动删除效果,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
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
来源: http://www.phperz.com/article/17/0722/292092.html