自定义有监听器的ScrollView
public class ObservableScrollView extends ScrollView { public ObservableScrollView(Context context) { super(context); } public ObservableScrollView(Context context, AttributeSet attrs) { super(context, attrs); } public ObservableScrollView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); } public interface OnScrollChangedListener { public void onScrollChanged(int x, int y, int oldX, int oldY); } private OnScrollChangedListener onScrollChangedListener; public void setOnScrollListener(OnScrollChangedListener onScrollChangedListener) { this.onScrollChangedListener = onScrollChangedListener; } @Override protected void onScrollChanged(int x, int y, int oldX, int oldY) { super.onScrollChanged(x, y, oldX, oldY); if (onScrollChangedListener != null) { onScrollChangedListener.onScrollChanged(x, y, oldX, oldY); } } }
参考自:http://stormzhang.com/android/2015/02/01/android-observable-scrollview/