Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ViewPager in a ListView - how to lock the scrolling axis?

I have a ViewPager widget in every row of a ListView. This provides a shelf-like UI, so the user can scroll around searching for a shelf vertically, and then scroll horizontally amongst the contents of a shelf. This works.

But the scrolling experience is terrible: if I start to drag a shelf's ViewPager, scroll it horizontally, and accidentally drag a bit upwards/downwards, then the ListView "traps" this dragging action, and start to scroll vertically, ending my horizontal drag. In this state, the drag action won't "return" to the ViewPager, the ListView has it, and that's it. I have to start another drag action to affect the ViewPager again. So I guess the ListView has precedence in these cases.

How can this be fixed? I'd like to achieve the exact opposite: If the ViewPager inside a list row starts reacting to a horizontal drag, then it should trap that action, and this drag should stop affecting the ListView, no matter how the user moves his/her finger vertically. Can this be done?

like image 592
Zsombor Erdődy-Nagy Avatar asked Oct 26 '11 09:10

Zsombor Erdődy-Nagy


People also ask

How do I stop ViewPager from scrolling?

A simple solution is to create your own subclass of ViewPager that has a private boolean flag, isPagingEnabled . Then override the onTouchEvent and onInterceptTouchEvent methods. If isPagingEnabled equals true invoke the super method, otherwise return .

Is ViewPager scrollable?

The ViewPager is populated with fragments taking up space way beyond the screen (vertically). Still, nothing on the screen is scrollable.

How do I make ListView scroll smoothly?

The key to a smoothly scrolling ListView is to keep the application's main thread (the UI thread) free from heavy processing. Ensure you do any disk access, network access, or SQL access in a separate thread. To test the status of your app, you can enable StrictMode .

Does ListView have scroll?

Listview so have inbuild scrolling capabilities. So you can not use listview inside scrollview.


1 Answers

I've found a solution in this thread. There the problem is to handle touch events properly for a HorizontalScrollView inside a regular ScrollView, but the solution to that problem seems to apply to this one too.

like image 174
Zsombor Erdődy-Nagy Avatar answered Oct 17 '22 16:10

Zsombor Erdődy-Nagy