• SwipeMenuListView在ScrollView里上下滑动导致菜单不能显示完全的bug解决方法


    这是因为上下滑动的时候,事件被ScrollView截获了,这时候应该禁止ScrollView截获上下滑动事件,解决方法如下

    public class NoRollSwipeMenuListView extends SwipeMenuListView {
    
        private GestureDetector mGestureDetector;
    
        public NoRollSwipeMenuListView(Context context) {
            super(context);
            mGestureDetector = new GestureDetector(context, onGestureListener);
        }
    
        public NoRollSwipeMenuListView(Context context, AttributeSet attrs) {
            super(context, attrs);
            mGestureDetector = new GestureDetector(context, onGestureListener);
        }
    
        public NoRollSwipeMenuListView(Context context, AttributeSet attrs, int defStyle) {
            super(context, attrs, defStyle);
            mGestureDetector = new GestureDetector(context, onGestureListener);
        }
    
        public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
            int expandSpec = MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE >> 2, MeasureSpec.AT_MOST);
            super.onMeasure(widthMeasureSpec, expandSpec);
        }
    
        @Override
        public boolean onTouchEvent(MotionEvent ev) {
            boolean b = mGestureDetector.onTouchEvent(ev);
    //        LogUtil.w("onTouchEvent", "mGestureDetector.onTouchEvent(ev)->" + b);
            return super.onTouchEvent(ev);
        }
    
        private GestureDetector.OnGestureListener onGestureListener = new GestureDetector.SimpleOnGestureListener() {
    
            //distanceX 左右滑动距离,左滑动正值,右滑动负值
            //distanceY 上下滑动距离,上滑动正值,下滑动负值
            @Override
            public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
                if (Math.abs(distanceY) >= Math.abs(distanceX)) {//上下滑动距离大于左右滑动距离,当作上下滑动
    //                LogUtil.w("onScroll", "distanceX=" + distanceX + ":distanceY=" + distanceY);
    //                LogUtil.w("onScroll", "true");
                    //上下滑动不做任何操作,在这里父ScrollView已经交出onTouch权限,否则如果权限在父ScrollView的话这里接收不到事件
                    //所以执行到这里是因为下面的setParentScrollAble(false);已经执行过了
                    return true;
                }
                //当滑动NoRollSwipeMenuListView的时候,让父ScrollView交出onTouch权限,也就是让父ScrollView停住不能滚动
                setParentScrollAble(false);
    //            LogUtil.w("onScroll", "false");
                return false;
            }
        };
    
        /**
         * 是否把滚动事件交给父ScrollView
         *
         * @param flag
         */
        private void setParentScrollAble(boolean flag) {
            //这里的parentScrollView就是NoRollSwipeMenuListView外面的那个ScrollView
    //        LogUtil.w("setParentScrollAble", "flag->" + flag);
            getParent().requestDisallowInterceptTouchEvent(!flag);
        }
    }
  • 相关阅读:
    [转载]在sharepoint里增加PDF图标显示收藏主题
    CuratorFramework开源Zookeeper快速开发框架介绍
    Zookeeper和CuratorFramework实践之:分布式消息队列
    Zookeeper和CuratorFramework实践系列之: 配置管理
    JS 文字向上滚动代码
    sql递归查询问题
    双线单IP和双线双IP机房的区别
    js获取标准北京时间
    ftp 21端口被占用解决办法
    "由于没有远程桌面授权服务器可以提供许可证..."不能远程桌面解决方法
  • 原文地址:https://www.cnblogs.com/supermanChao/p/5832577.html
Copyright © 2020-2023  润新知