IFirst Create a custom class that extends ScrollView, and create a listener that has the method onScrollChanged as here:
public class ProductDetailScrollView extends ScrollView { public interface OnScrollChangedListener { void onScrollChanged(ScrollView who, int l, int t, int oldl, int oldt); } private OnScrollChangedListener mOnScrollChangedListener; public void setOnScrollChangedListener(OnScrollChangedListener listener) { mOnScrollChangedListener = listener; } @Override protected void onScrollChanged(int l, int t, int oldl, int oldt) { super.onScrollChanged(l, t, oldl, oldt); if (mOnScrollChangedListener != null) { mOnScrollChangedListener.onScrollChanged(this, l, t, oldl, oldt); } } public ProductDetailHorizontalScrollView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); } public ProductDetailHorizontalScrollView(Context context, AttributeSet attrs) { super(context, attrs); } public ProductDetailHorizontalScrollView(Context context) { super(context); } } Then i create a variable (in the activity) mOnScrollChangedListener, and set it as the listener for mScrollView:
private ScrollViewProductDetailScrollView.OnScrollChangedListener mOnScrollChangedListener = new ProductDetailScrollView.OnScrollChangedListener() { public void onScrollChanged(ScrollView who, int l, int t, int oldl, int oldt) { System.out.println("Scrolled: " + t); //Parallax Effect on scroll if (t > 0) { final float newY = (t / 4.0f) * -1.0f; mProductImageContainer.setY(newY); } else { mProductImageContainer.setY(0.0f); } } };