当前位置: 代码迷 >> Android >> android监听ScrollView滑动终止
  详细解决方案

android监听ScrollView滑动终止

热度:21   发布时间:2016-05-01 13:35:23.0
android监听ScrollView滑动停止

思路是当滑动开始时不停的监听scrollview的高度,当高度不变时说明滑动已经停止

 scrollView.setOnTouchListener(new OnTouchListener() {        	   private int lastY = 0;        	   private int touchEventId = -9983761;        	   Handler handler = new Handler() {        	    @Override        	    public void handleMessage(Message msg) {        	     super.handleMessage(msg);        	     View scroller = (View)msg.obj;        	     if(msg.what==touchEventId) {        	      if(lastY ==scroller.getScrollY()) {        	       handleStop(scroller);        	      }else {        	       handler.sendMessageDelayed(handler.obtainMessage(touchEventId,scroller), 1);        	       lastY = scroller.getScrollY();        	      }        	     }        	    }        	   };        	   @Override        	   public boolean onTouch(View v, MotionEvent event) {        		    isScoll = false;        	    	int eventAction = event.getAction();		int y=(int) event.getRawY();		switch (eventAction) {		case MotionEvent.ACTION_UP:			if(Math.abs(touchY-y)<20){			}else{			     handler.sendMessageDelayed(handler.obtainMessage(touchEventId,v), 5);			 }			 break;		default:			break;		}		return false;        	   }        	   //这里写真正的事件        	   private void handleStop(Object view) {//        		          	  }        });

?

  相关解决方案