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

后端 未结 9 968
深忆病人
深忆病人 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条回答
  •  萌比男神i
    2020-11-27 14:03

    Apply a transparent image over the mapview fragment.

    
    
        
    
        
    
       
    

    Then set requestDisallowInterceptTouchEvent(true) for the main ScrollView. When the user touches the transparent image and moves disable the touch on the transparent image for MotionEvent.ACTION_DOWN and MotionEvent.ACTION_MOVE so that map fragment can take Touch Events.

    ScrollView mainScrollView = (ScrollView) findViewById(R.id.main_scrollview);
    ImageView transparentImageView = (ImageView) findViewById(R.id.transparent_image);
    
    transparentImageView.setOnTouchListener(new View.OnTouchListener() {
    
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            int action = event.getAction();
            switch (action) {
               case MotionEvent.ACTION_DOWN:
                    // Disallow ScrollView to intercept touch events.
                    mainScrollView.requestDisallowInterceptTouchEvent(true);
                    // Disable touch on transparent view
                    return false;
    
               case MotionEvent.ACTION_UP:
                    // Allow ScrollView to intercept touch events.
                    mainScrollView.requestDisallowInterceptTouchEvent(false);
                    return true;
    
               case MotionEvent.ACTION_MOVE:
                    mainScrollView.requestDisallowInterceptTouchEvent(true);
                    return false;
    
               default: 
                    return true;
            }   
        }
    });
    

    This worked for me. Hope it helps you..

提交回复
热议问题