Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Nested scrolling on Android

Tags:

android

We have a main horizontal scroll view in our activity, and several vertical scroll views nested inside it. The idea is to scroll horizontally till you find the vertical list you want, then scroll that up and down.

Ideally, I'd want the vertical scrolling to have a "lock" once you start scrolling vertically. What happens now, if you're very careful, you can scroll vertically, but if you move your finger a little too much to the left/right while doing it, the vertical stops and the horizontal takes over.

What would probably make sense is, whatever scroll view gets "activated" first by your movement, that one stays active until you finish your interaction (ie remove your finger).

Any way to make it behave like that?

like image 221
Kevin Galligan Avatar asked Aug 16 '11 15:08

Kevin Galligan


People also ask

What is the difference between nested scroll view and scroll view?

NestedScrollView is just like ScrollView, but in NestedScrollView we can put other scrolling views as child of it, e.g. RecyclerView. But if we put RecyclerView inside NestedScrollView, RecyclerView's smooth scrolling is disturbed.

Can scroll horizontally android?

HorizontalScrollView is used to scroll the child elements or views in a horizontal direction. HorizontalScrollView only supports horizontal scrolling. For vertical scroll, android uses ScrollView.


1 Answers

It may be better to use a ViewPager for the horizontal swiping, if it would work for your app.

If that wouldn't work, try overriding the onTouch method of the vertical ScrollViews so that they prevent the horizontal scroll view from scrolling using

  scrollView.setEnabled(false)

Having ScrollViews nested inside of other ScrollViews is generally a bad practice since it is usually harder for the user to navigate, so you may need to consider redesigning that Activity to avoid this problem.

If you must use nested ScrollViews, I found this two-dimensional ScrollView class that may help you.

like image 79
starkej2 Avatar answered Nov 14 '22 23:11

starkej2