Android 开源项目浅读-------SwipeMenuListView-重写,第七章,菜单停留和暂停响应
来源:互联网 发布:2017七天网络成绩查询 编辑:程序博客网 时间:2024/05/01 13:16
这一个章节实现菜单的停留和当一个菜单打开时候,其它菜单暂停打开响应。
实现菜单停留其实很简单,就是当手指弹起来的时候判断滑动的距离就行了。修改SwipeMenuLayout类里面的哦你Swipe函数中ACTION_UP响应,另外参考源码修改一下mMenuView.layout函数的坐标,就可以实现了。
case MotionEvent.ACTION_UP: Log.i(TAG, "Action up"); if(Math.abs(event.getX() - mDownX)>mMenuView.getWidth()/2){ mContentView.layout(0, 0, getMeasuredWidth(), mContentView.getMeasuredHeight()); mMenuView.layout(getMeasuredWidth()- mMenuView.getWidth(), 0, getMeasuredWidth(),mContentView.getBottom()); }else { mOpenScroller.startScroll((int)event.getX(),0,this.getWidth()-(int)event.getX(), 0,1000); mContentView.layout(0,0,getMeasuredWidth(), mContentView.getMeasuredHeight()); }
如果出现mMenuView的宽带是屏幕宽度,请在onMeasure里面添加源码
@Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { super.onMeasure(widthMeasureSpec, heightMeasureSpec); Log.i(TAG, "onMeasure " + mMenuView.getWidth() + " , mMenuView getMeasuredWidth is" + mMenuView.getMeasuredWidth()); mMenuView.measure(MeasureSpec.makeMeasureSpec(600, MeasureSpec.AT_MOST), MeasureSpec.makeMeasureSpec( getMeasuredHeight(), MeasureSpec.EXACTLY)); }
接下来实现当一个菜单打开时候,其它菜单不响应。这个做的话,就是加个标志变量state,大家可以参考一下源码中的state变量,在ACITON_UP之后就设置state的状态。
private static final int STATE_CLOSE = 0; private static final int STATE_OPEN = 1; private int state = STATE_CLOSE; public boolean isOpen(){ return state == STATE_OPEN; }
case MotionEvent.ACTION_UP: Log.i(TAG, "Action up"); if(Math.abs(event.getX() - mDownX)>mMenuView.getWidth()/2){ state = STATE_OPEN; mContentView.layout(0, 0, getMeasuredWidth(), mContentView.getMeasuredHeight()); mMenuView.layout(getMeasuredWidth()- mMenuView.getWidth(), 0, getMeasuredWidth(),mContentView.getBottom()); }else { state = STATE_CLOSE; mOpenScroller.startScroll((int)event.getX(),0,this.getWidth()-(int)event.getX(), 0,1000); mContentView.layout(0,0,getMeasuredWidth(), mContentView.getMeasuredHeight()); } //postInvalidate(); // mMenuView.layout(getMeasuredWidth(), 0 , getMeasuredWidth()+ mMenuView.getMeasuredWidth(), mMenuView.getBottom()); break;
在SwipeMenuListView的ACTION_DOWM里面会判断这个值。
case MotionEvent.ACTION_DOWN: int oldPosition = mTouchPosition; Log.i(TAG, "Action Down"); if(mTouchView != null && mTouchView.isOpen() ){ return true; } mTouchPosition = pointToPosition((int)ev.getX(),(int)ev.getY()); view = getChildAt(mTouchPosition - getFirstVisiblePosition()); if(view instanceof SwipeMenuLayout){ mTouchView =(SwipeMenuLayout)view; mTouchView.setPosition(mTouchPosition); mTouchView.onSwipe(ev); }
最终效果如图
点击下载
0 0
- Android 开源项目浅读-------SwipeMenuListView-重写,第七章,菜单停留和暂停响应
- Android 开源项目浅读-------SwipeMenuListView-重写,八章,菜单响应
- Android 开源项目浅读-------SwipeMenuListView-重写-第二章,菜单显示
- Android 开源项目浅读-------SwipeMenuListView-重写,第三章,随手指移动的菜单
- Android 开源项目浅读-------SwipeMenuListView-重写,第四章,修改适配器
- Android 开源项目浅读-------SwipeMenuListView-重写,第五章,滑动弹出,放手关闭功能实现
- Android 开源项目浅读-------SwipeMenuListView-重写,第六章,缓慢收回
- Android 开源项目浅读-------SwipeMenuListView-重写-第一章-手指移动事件捕获
- Android 开源项目浅读-------SwipeMenuListView
- 开源项目SwipeMenuListView使用
- 开源项目SwipeMenuListView学习笔记
- (开源工具)SwipeMenuListView滑动菜单的使用
- Android仿qq下拉刷新及向左滑动列表----PullToRefresh, SwipeMenuListView开源项目整合
- Android仿qq下拉刷新及向左滑动列表----PullToRefresh, SwipeMenuListView开源项目整合
- Android仿qq下拉刷新及向左滑动列表----PullToRefresh, SwipeMenuListView开源项目整合
- 关于开源项目SwipeMenuListView的使用详解
- 仿Android QQ左侧滑菜单右侧滑列表菜单——处理HorizontalScrollView和SwipeMenuListView滑动冲突
- Android可左右滑动的ListView开源框架SwipeMenuListView
- 《基于双经度模型的鱼眼图像畸变校正方法》code
- 字符串倒序输出
- [bzoj 1613]: [Usaco2007 Jan]Running贝茜的晨练计划 dp
- sqlite3命令语句, 文档小记
- Codeforces 96A: Football(水题)
- Android 开源项目浅读-------SwipeMenuListView-重写,第七章,菜单停留和暂停响应
- ButterKnife源码分析
- 反思今天所做所为
- unity中结合oculus制作VR场景控制相机的移动的三种方式
- jQuery中ajax的基本使用(2)
- CentOS 7 安装好后,无法使用小键盘的解决办法
- ACM:搜索算法专题(1)——24点
- Android 连续点击实现一些隐蔽功能
- int main( int argc ,char** argv) windows下如何传递参数