protected void onScrollChanged(int x, int y, int oldx, int oldy);想要实现监听需要简单自定义组件.
public class ObservableScrollView extends HorizontalScrollView { private ScrollViewListener scrollViewListener = null; public ObservableScrollView(Context context) { super(context); } public ObservableScrollView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); } public ObservableScrollView(Context context, AttributeSet attrs) { super(context, attrs); } public void setScrollViewListener(ScrollViewListener scrollViewListener) { this.scrollViewListener = scrollViewListener; } @Override protected void onScrollChanged(int x, int y, int oldx, int oldy) { super.onScrollChanged(x, y, oldx, oldy); if (scrollViewListener != null) { scrollViewListener.onScrollChanged(this, x, y, oldx, oldy); } } }
public interface ScrollViewListener { void onScrollChanged(ObservableScrollView scrollView, int x, int y, int oldx, int oldy); }
horizontalScrollView.setScrollViewListener(new ScrollViewListener() {//滑动监听,获取图片 @Override public void onScrollChanged(ObservableScrollView scrollView, int x, int y, int oldx, int oldy) { int scrollX = scrollView.getScrollX(); int width = scrollView.getWidth(); int scrollViewMeasuredWidth = holder.imageSL.getChildAt(0).getMeasuredWidth(); if ((scrollX + width) == scrollViewMeasuredWidth) { // System.out.println("滑动到了底部 scrollY=" + scrollX + "height=" + width + "scrollViewMeasuredHeight=" + scrollViewMeasuredWidth); } } });
ScrollView的滑动监听(以HorizontalScrollView为例)
原文地址:http://blog.csdn.net/pengkv/article/details/43203085