Parallax at its simplest — with ScrollView

Saurabh Pant
1 min readSep 19, 2017

Finding the simplest way of doing something is the hardest.

We all have been using parallax effect on views for intuitiveness in user interface. I always wondered that do I’ve to use some third party library to achieve this task? Well no more!

Here is the simplest way with which you can create a parallax effect using ScrollView. So let’s get started.

Firstly, we need to have a scroll listener on ScrollView and we can add it one by using the following code on ScrollView object.

scrollView.getViewTreeObserver().addOnScrollChangedListener(ScrollListener);

Secondly, we just need to calculate the translation factor to shift our views upwards/downwards. Below is the complete code you need to achieve this.

From my Github gist
Without scroll
With parallax

Hope it’ll help you some way.

Happy and Simple Coding! :)

Cheers!

--

--

Saurabh Pant

App Developer (Native & Flutter) | Mentor | Writer | Youtuber @_zaqua | Traveller | Content Author & Course Instructor @Droidcon | Frontend Lead @MahilaMoney