0

I am working on an app on android which simulates parallax scrolling with a top scrollview, the content and the bottom scroll view.

I would like to scroll using only the middle scrollview, but I am able to independently scroll the top view manually. This I would like to prevent.

I tried this from another related question, but this seems to disable scrolling in this case.. What I would like is for the touch to fall through to the 2nd layer and for that to handle the scrolling.

.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View view, MotionEvent motionEvent) { return true; } });

Is this a call for onInterceptTouchEvent? I am still trying to understand that. Let me know if this is not enough information or if it isnt clear.

tl;dr - I want my scroll view to be completely passive touch wise, act as if it doesn't exist, and pass the touch to lower layers.

2 Answers 2

1

This is just an idea and I haven't tested it but I think the following steps should work:

1.On your top scrollView,intercept the onTouch event(monitor especially the ACTION_MOVE event);

2.Take a handle of the scrollview that you actually want to move. and use ScrollView.smoothScrollto(int x,int y) function to move that scrollView programmatically.Pass the getX() and getY() values that you receive in this motionEvent, thus allowing you to pass the touch to lower layers.

refer the android doc of smoothScrollto for clarity.

3.Obviously as a last note , you should be swallowing the touches on the lower scrollView that you'll be moving programmatically.This will avoid the lower scrollView to move on its own onTouch.

Since you said you want to implement parallax you can multiply the x and y values received in step #2 by some factor thus creating a parrallax effect.

You can easily find code snippets for above steps on SO. Best of luck!

EDIT : refer this link if you want to get the onScroll event when the uppermost scrollView scrolls.

Sign up to request clarification or add additional context in comments.

Comments

0

My solution is inspired by @Parvaz Bhaskar's solution, but a lot simpler... indeed so simple that i'm surprised that it didn't occur to me when i thought of my question.

To pass the touch to the layer below... I just pass the touch to the layer below

grassView.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View view, MotionEvent motionEvent) { mViewPager.onTouchEvent(motionEvent); //Scroll the view pager so that scrolling works through the grass. return true; // NO SCROLLING FOR YOU! http://stackoverflow.com/a/10481239/1520364 } }); 

In my case I have a layer on top which is the grassView here, and a view pager below which has my actual tabs that that need to scroll. So I swallow the touch on the grass level, and pass it to my ViewPager

2 Comments

okay, I thought you had two scroll views and wanted to move both scroll views but with a parallax effect. Anyways good to know I helped!
@ParvazBhaskar Yeah, the parallax is already implemented, I added a layer on top, so my concern was to just pass it down to the middle layer which then implemented the parallax

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.