1.监听ScrollView滑动停止:

 




 


  1. /********************监听ScrollView滑动停止*****************************/  
  2. scrollView.setOnTouchListener(new OnTouchListener() {  
  3.     private int lastY = 0;  
  4.     private int touchEventId = -9983761;  
  5.     Handler handler = new Handler() {  
  6.         @Override  
  7.         public void handleMessage(Message msg) {  
  8.             super.handleMessage(msg);  
  9.             View scroller = (View) msg.obj;  
  10.             if (msg.what == touchEventId) {  
  11.                 if (lastY == scroller.getScrollY()) {  
  12.                     handleStop(scroller);  
  13.                 } else {  
  14.                     handler.sendMessageDelayed(handler.obtainMessage(touchEventId, scroller), 5);  
  15.                     lastY = scroller.getScrollY();  
  16.                 }  
  17.             }  
  18.         }  
  19.     };  
  20.   
  21.   
  22.     public boolean onTouch(View v, MotionEvent event) {  
  23.         if (event.getAction() == MotionEvent.ACTION_UP) {  
  24.             handler.sendMessageDelayed(handler.obtainMessage(touchEventId, v), 5);  
  25.         }  
  26.         return false;  
  27.     }  
  28.   
  29.   
  30.     private void handleStop(Object view) {  
  31.         ScrollView scroller = (ScrollView) view;  
  32.         scrollY = scroller.getScrollY();  
  33.     }  
  34. });  
  35. /***********************************************************/  



 

 

 

2.监听ScrollView滑动到底部:

 




 


  1. package com.example.webviewdemo;  
  2.   
  3. import android.content.Context;  
  4. import android.util.AttributeSet;  
  5. import android.widget.ScrollView;  
  6.   
  7. public class ScrollBottomScrollView extends ScrollView {  
  8.   
  9.     private ScrollBottomListener scrollBottomListener;  
  10.   
  11.     public ScrollBottomScrollView(Context context) {  
  12.         super(context);  
  13.     }  
  14.   
  15.     public ScrollBottomScrollView(Context context, AttributeSet attrs) {  
  16.         super(context, attrs);  
  17.     }  
  18.   
  19.     public ScrollBottomScrollView(Context context, AttributeSet attrs,int defStyle) {  
  20.         super(context, attrs, defStyle);  
  21.     }  
  22.   
  23.     @Override  
  24.     protected void onScrollChanged(int l, int t, int oldl, int oldt){  
  25.         if(t + getHeight() >=  computeVerticalScrollRange()){  
  26.             //ScrollView滑动到底部了  
  27.             scrollBottomListener.scrollBottom();  
  28.         }  
  29.     }  
  30.   
  31.     public void setScrollBottomListener(ScrollBottomListener scrollBottomListener){  
  32.         this.scrollBottomListener = scrollBottomListener;  
  33.     }  
  34.   
  35.     public interface ScrollBottomListener{  
  36.         public void scrollBottom();  
  37.     }  
  38.   
  39. }