Android Fixed Background ScrollView

4 minute read

It's a fun feature, particularly on high-content Activities, but an issue we encountered was if we wanted to have links or other interface elements on the lower, static layer. This problem was caused by the ScrollView which contained the upper layer's content. Because it was positioned on top of the background, the ScrollView was intercepting the touch events for the entire Activity. This includes where the ScrollView's padding creates the clear transparent region through which the lower layer can be seen.

The approach to solving this problem involves implementing a custom ScrollView which override's the onTouchEvent handling: if this returns false, the ScrollView does not handle the touch event, which gets passed to successively lower views looking for a claimant.

After a few attempts at specifying a particular height for the "clickable" and "scrollable" areas, which ultimately failed due to the relative complexity of handling the "fling" behaviour; we settled on an approach which instead used the MotionEvent's action property:

This can be used in XML as follows:

Written by Simon Bos (Founder/Director). Read more in Insights by Simon or check our their socials Twitter, Instagram