Google Maps API v2 SupportMapFragment inside ScrollView - users cannot scroll the map vertically

后端 未结 9 959
深忆病人
深忆病人 2020-11-27 13:01

I am trying to put a Google map inside a scroll view, so that the user can scroll down other contents to see the map. The problem is that this scroll view is eating up all t

9条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-11-27 13:46

    I encountered a similar problem and came up with a more general working solution based on In-Ho Yi and Данаил Димитров answers above.

    public class CustomScrollView extends ScrollView {
    
        List mInterceptScrollViews = new ArrayList();
    
        public CustomScrollView(Context context) {
            super(context);
        }
    
        public CustomScrollView(Context context, AttributeSet attrs) {
            super(context, attrs);
        }
    
        public CustomScrollView(Context context, AttributeSet attrs, int defStyle) {
            super(context, attrs, defStyle);
        }
    
        public void addInterceptScrollView(View view) {
            mInterceptScrollViews.add(view);
        }
    
        public void removeInterceptScrollView(View view) {
            mInterceptScrollViews.remove(view);
        }
    
        @Override
        public boolean onInterceptTouchEvent(MotionEvent event) {
    
            // check if we have any views that should use their own scrolling
            if (mInterceptScrollViews.size() > 0) {
                int x = (int) event.getX();
                int y = (int) event.getY();
                Rect bounds = new Rect();
    
                for (View view : mInterceptScrollViews) {
                    view.getHitRect(bounds);
                    if (bounds.contains(x, y + scrollY)) {
                        //were touching a view that should intercept scrolling
                        return false;
                    }
                }
            }
    
            return super.onInterceptTouchEvent(event);
        }
    }
    

提交回复
热议问题