Possible Duplicate:
gesture issue with mapview in viewpager page
I use the template that allow us to swipe horizontally between tabs
But one of my tab is MapView, so when I swipe left/right in that MapView, it will switch tab instead of moving the map.
Is there any way to disable the gesture only in that MapView tab?
Thanks
I found the answer from this question
In case the link is dead, I copied the code here:
Make a new class with this exact code, it will prevent MapView to receive any other gesture aside of map-related gesture. Don't forget to add your package and import (CTRL+SHIFT+O) above these code
public class CustomViewPager extends ViewPager {
public CustomViewPager(Context context) {
super(context);
}
public CustomViewPager(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
protected boolean canScroll(View v, boolean checkV, int dx, int x, int y) {
if (v instanceof MapView) {
return true;
}
return super.canScroll(v, checkV, dx, x, y);
}
}
Then in main.xml change the <android.support.v4.view.ViewPager ... /> into this:
<com.yourPackage.CustomViewPager
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/pager"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".Main" />
Thanks to Jorge Aguilar for the answer in that question!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With