zoukankan      html  css  js  c++  java
  • android 在一个scrollView里面嵌套一个需要滑动的控件(listView、gridView)

    package cn.via.dageeeOrderFood.widget;
    
    import android.content.Context;
    import android.graphics.PointF;
    import android.util.AttributeSet;
    import android.view.MotionEvent;
    import android.widget.ListView;
    
    /**
     * Created by Heyiyong on 2014-2-27 下午10:34.
     */
    public class MyListView extends ListView {
    
        /** 触摸时按下的点 **/
        PointF downP = new PointF();
        /** 触摸时当前的点 **/
        PointF curP = new PointF();
    
        public MyListView(Context context, AttributeSet attrs) {
            super(context, attrs);
        }
    
        public MyListView(Context context) {
            super(context);
        }
    
        public MyListView(Context context, AttributeSet attrs, int defStyle) {
            super(context, attrs, defStyle);
        }
    
        @Override
        public boolean onInterceptTouchEvent(MotionEvent arg0) {
            //当拦截触摸事件到达此位置的时候,返回true,
            //说明将onTouch拦截在此控件,进而执行此控件的onTouchEvent
            return true;
        }
    
        @Override
        public boolean onTouchEvent(MotionEvent arg0) {
            //每次进行onTouch事件都记录当前的按下的坐标
            curP.x = arg0.getX();
            curP.y = arg0.getY();
    
            if(arg0.getAction() == MotionEvent.ACTION_DOWN){
                //记录按下时候的坐标
                //切记不可用 downP = curP ,这样在改变curP的时候,downP也会改变
                downP.x = arg0.getX();
                downP.y = arg0.getY();
                //此句代码是为了通知他的父ViewPager现在进行的是本控件的操作,不要对我的操作进行干扰
                getParent().requestDisallowInterceptTouchEvent(true);
            }
    
            if(arg0.getAction() == MotionEvent.ACTION_MOVE){
                //此句代码是为了通知他的父ViewPager现在进行的是本控件的操作,不要对我的操作进行干扰
                getParent().requestDisallowInterceptTouchEvent(true);
            }
    
            if(arg0.getAction() == MotionEvent.ACTION_UP){
                //在up时判断是否按下和松手的坐标为一个点
                //如果是一个点,将执行点击事件,这是我自己写的点击事件,而不是onclick
                if(downP.x==curP.x && downP.y==curP.y){
                   /* onSingleTouch();*/
                    return true;
                }
            }
    
            return super.onTouchEvent(arg0);
        }
    
    }
  • 相关阅读:
    在EasyDarwin进行实时视频转发的两种模式
    Windows服务中读取配置文件的方法
    reactor设计模式
    用Darwin实现流媒体转发程序(附源码)
    Windows服务中读取配置文件的方法
    c# 参数 this
    基于DSS的先侦听后推送式流媒体转发
    用live555做本地视频采集转发,附源码
    Darwin在转发流过程中对推送端断开的处理问题
    基于live555的流媒体代理转发服务器
  • 原文地址:https://www.cnblogs.com/wuyou/p/3578331.html
Copyright © 2011-2022 走看看