ScrollView判断滑动到底部和顶部

scroll_view.setOnTouchListener(new View.OnTouchListener() {
                @Override
                public boolean onTouch(View v, MotionEvent event) {
                    // 判断 scrollView 当前滚动位置在顶部
                    if(scroll_View.getSrollY == 0){
                    }
    
                    // 判断scrollview 滑动到底部
                    // scrollY 的值和子view的高度一样,这人物滑动到了底部
                    if (scroll_view.getChildAt(0).getHeight() - scroll_view.getHeight() 
                                == scroll_view.getScrollY()){
                    }
                    return false;
                }
            });

HorizontalScrollView:

 @Override  
  protected void onScrollChanged(int l, int t, int oldl, int oldt) {  
    // TODO Auto-generated method stub  
    super.onScrollChanged(l, t, oldl, oldt);  
    int  maxScrollX = getChildAt(0).getMeasuredWidth()-getMeasuredWidth();   
      //滑到最左  
      if (getScrollX() == 0 ) {   
          
      }else if (getScrollX() == maxScrollX) {  //滑到最右  
          
}else {  //滑到中间  
  
}  
  } 

你可能感兴趣的:(ScrollView判断滑动到底部和顶部)