MapView in a ViewPager don't scroll horizontally
See original GitHub issueIssue Type
[x] Bug [x] Improvement
Description
A MapView in a ViewPager can’t scroll horizontally because the ViewPager intercept the scroll gesture and swipe the views. Note that vertical scrolling works fine.
After searching around a solution was found by adding two lines in the onTouchEvent()
method:
@Override
public boolean onTouchEvent(MotionEvent event) {
// Prevent the ViewPager to swipe its views
// See https://stackoverflow.com/questions/8594361/horizontal-scroll-view-inside-viewpager
if (event.getAction() == MotionEvent.ACTION_MOVE && getParent() != null) {
getParent().requestDisallowInterceptTouchEvent(true);
}
return false;
}
This could be enhanced by detecting (in an ACTION_DOWN
) that the user initiate the scroll near the left or right border and then not calling requestDisallowInterceptTouchEvent(true)
in that case.
This was suggested here
My 2 cents Yves
Issue Analytics
- State:
- Created 6 years ago
- Comments:11
Top Results From Across the Web
gesture issue with mapview in viewpager page - Stack Overflow
My problem is that if the user is on the map page and uses a horizontal slide gesture, the page slides to the...
Read more >Manage touch events in a ViewGroup - Android Developers
MyViewGroup contains multiple child views. If you drag your finger across a child view horizontally, the child view should no longer get touch ......
Read more >Bug: Black rectangle background on scroll [35822196]
When I do the scroll of ViewPager, or do a vertical Scroll (scrollBy) in the fragment, the Map leaves behind a black rectangle,...
Read more >Googlemap Does Not Load Inside Viewpager - ADocLib
The listview has its own scrolling rules that become difficult to deal with when you try ... when you think that the ViewPager...
Read more >The Making of Prixing #2: Swiping the Fly-in App Menu
In Prixing, the main problem we had was to imbricate horizontally scrollable components ( ViewPager , MapView , etc.) ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I use 5% of map width for left limit and 95% for right limit
Sorry just saw i made a mistake in the above code. Should be read as:
Sorry.
looks great! i’ll add it to the wiki