【android】判断HorizontalScrollView/ScrollView滑到最左/上和最右/下

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:

只需将上面代码中的ScrollX改为ScrollY,MeasuredWidth改为MeasuredHeight即可




参考http://stackoverflow.com/questions/9597943/how-to-detect-that-the-horizontalscrollview-has-reached-an-end

你可能感兴趣的:(android)