import android.content.Context; import android.util.AttributeSet; import android.widget.ScrollView; /** * 提供setScrollViewListener函數的ScrollView * User: Jerry * Date: 13-3-11 * Time: 下午6:27 */ public class ObservableScrollView extends ScrollView{ private ScrollViewListener scrollViewListener = null; 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 void setScrollViewListener(ScrollViewListener listener) { this.scrollViewListener = listener; } @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); } }