gesture issue with mapview in viewpager page

后端 未结 2 1438
南旧
南旧 2020-12-08 10:53

My app\'s main interface is a viewpager where the user just slides the pages horizontally to get to the various pages. One of the pages has a google mapview (pasted below).

相关标签:
2条回答
  • 2020-12-08 11:28

    If using Google Maps V2, use

    scrollingView.getClass().getPackage().getName().startsWith("maps.") in canScroll method:

    @Override
    protected boolean canScroll(View scrollingView, boolean checkV, int dx, int x, int y) {
        if (scrollingView.getClass().getPackage().getName().startsWith("maps.")) {
            return true;
        }
        return super.canScroll(scrollingView, checkV, dx, x, y);
    }
    

    Becase scrollingView is maps.j.b when using maps v2.

    Also in my code, these classes are used:

    import com.google.android.gms.maps.GoogleMap;
    import com.google.android.gms.maps.SupportMapFragment;
    
    0 讨论(0)
  • 2020-12-08 11:33

    Of course there is:

    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);
        }
    
    }
    

    This will make the map ignore all the slides inside the map and just care about the slides/draggs outside the map. Hope it helps. (I do this right now for a webview with horizontal scroll)

    EDIT: Forgot to mention that instead of the ViewPager you need to use the CustomViewPager in yout layout.

    <com.yourpackage.CustomViewPager
                android:id="@+id/viewpager"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent" 
            />
    
    0 讨论(0)
提交回复
热议问题