android 模仿自带的notifacation提示左右滑动删除Listveiw的item项
来源:互联网 发布:淘宝购买须知模板 编辑:程序博客网 时间:2024/05/17 03:37
先来个效果图吧:
可以左右拖动,并且在拖动过程中慢慢变透明....(没有在真机上测试)
下面是主要代码,些的很烂,改进的地方还有很多哦,放在这学习一下了.....
package com.xy.android.wireless.orderdishes.processdata;import java.util.List;import android.view.MotionEvent;import android.view.View;import android.view.View.OnTouchListener;import android.view.animation.Animation;import android.view.animation.AnimationSet;import android.view.animation.AnimationUtils;import android.view.animation.Animation.AnimationListener;import android.view.animation.TranslateAnimation;import android.widget.ListView;import com.zte.android.wireless.orderdishes.adapter.util.DetailsListAdapter;import com.zte.android.wireless.orderdishes.server.R;/** * @version 创建时间:2012-11-20 下午3:43:09 类说明 */public class deleteListViewItem implements OnTouchListener {private List<DishInfo> list;// 传进来的list数据private DetailsListAdapter adapter;// 传进来的列表适配器public deleteListViewItem(List<DishInfo> list, DetailsListAdapter adapter) {this.list = list;this.adapter = adapter;}float x = 0, y = 0;int sum;int temp;boolean mFlag = false;float alpha = 1f;@Overridepublic boolean onTouch(View view, MotionEvent event) {float upx = 0, upy = 0, movex = 0;int position = 0;if (event.getAction() == MotionEvent.ACTION_DOWN) {x = event.getX();y = event.getY();}position = ((ListView) view).pointToPosition((int) x, (int) y);if (event.getAction() == MotionEvent.ACTION_MOVE) {movex = event.getX();if (mFlag) {if (temp > movex) {((ListView) view).getChildAt(position).scrollBy((int) (3),0);alpha += 0.01f;((ListView) view).getChildAt(position).setAlpha(alpha);sum -= 3;}}if ((x - movex) < 0) {if (Math.abs(x - movex) > ((ListView) view).getChildAt(position).getWidth() * 0.8) {View v = ((ListView) view).getChildAt(position);deleteListItem(v, position);}((ListView) view).getChildAt(position).scrollBy((int) (-3), 0);alpha -= 0.01f;((ListView) view).getChildAt(position).setAlpha(alpha);sum += 3;temp = (int) movex;mFlag = true;}}if (event.getAction() == MotionEvent.ACTION_UP) {upx = event.getX();upy = event.getY();int position1 = ((ListView) view).pointToPosition((int) x, (int) y);int position2 = ((ListView) view).pointToPosition((int) upx,(int) upy);if (position1 == position2 && Math.abs(x - upx) > 200) {if (x < upx) {View v = ((ListView) view).getChildAt(position);deleteListItem(v, position);alpha = 1f;((ListView) view).getChildAt(position).scrollBy((int) sum,0);((ListView) view).getChildAt(position).setAlpha(alpha);}} else {alpha = 1f;((ListView) view).getChildAt(position).setAlpha(alpha);((ListView) view).getChildAt(position).clearFocus();((ListView) view).getChildAt(position).scrollBy((int) sum, 0);sum = 0;}position = 0;sum = 0;}return false;}protected void deleteListItem(View rowView, final int positon) {Animation animation = (Animation) AnimationUtils.loadAnimation(rowView.getContext(), R.anim.item_anim);animation.setAnimationListener(new AnimationListener() {public void onAnimationStart(Animation animation) {}public void onAnimationRepeat(Animation animation) {}public void onAnimationEnd(Animation animation) {System.out.println("list.size--->>>" + list.size());list.remove(positon);adapter.notifyDataSetChanged();animation.cancel();}});rowView.startAnimation(animation);}}
- android 模仿自带的notifacation提示左右滑动删除Listveiw的item项
- HorizontalDragLayout-模仿QQ客户端的Item滑动删除
- HorizontalDragLayout-模仿QQ客户端的Item滑动删除
- android 实现Listview左右滑动删除Item
- android listview item 左右滑动删除
- ListView 实现带有Filpper效果的左右滑动删除 Item
- Android 使用Scroller实现绚丽的ListView左右滑动删除Item效果
- Android 使用Scroller实现绚丽的ListView左右滑动删除Item效果
- Android 使用NineOldAndroids实现绚丽的ListView左右滑动删除Item效果
- Android 使用NineOldAndroids实现绚丽的ListView左右滑动删除Item效果
- Android 使用Scroller实现绚丽的ListView左右滑动删除Item效果
- Android 使用NineOldAndroids实现绚丽的ListView左右滑动删除Item效果
- Android 使用Scroller实现绚丽的ListView左右滑动删除Item效果
- Android 使用NineOldAndroids实现绚丽的ListView左右滑动删除Item效果
- Android 使用Scroller实现绚丽的ListView左右滑动删除Item效果
- Android 使用NineOldAndroids实现绚丽的ListView左右滑动删除Item效果
- Android 使用Scroller实现绚丽的ListView左右滑动删除Item效果
- Android 使用Scroller实现绚丽的ListView左右滑动删除Item效果
- C语言编写windows用户账户管理
- 最新SpringMVC + spring3.1.1 + hibernate4.1.0 集成及常见问题总结
- log4j实现日志集中存储
- Java语言提供的对观察者模式的支持
- Python中else语句整理
- android 模仿自带的notifacation提示左右滑动删除Listveiw的item项
- 优秀的程序 vs. 糟糕的程序
- VC/MFC中计算程序运行时间
- Ubuntu 12.04 下编译Android 4.0.3
- Android Messenger 跨进程通信!!!!!!!!!!!!!!!!!!
- linux环境下C/C++性能测试工具 gprof 和gprof2dot
- ElasticSearch-bigdesk插件安装
- 排序算法
- 标准核酸代码表