how to set google map fragment inside scroll view

后端 未结 8 974
北海茫月
北海茫月 2020-11-29 00:00

I want to set a Google map fragment inside vertical ScrollView, when I do the map does not zoom vertically, how can I override the touch event listener on

8条回答
  •  旧时难觅i
    2020-11-29 00:12

    Please refer to this answer: https://stackoverflow.com/a/17317176/4837103

    It creates a transparent view with the same size of mapFragment, at the same position with mapFragment, then invoke requestDisallowInterceptTouchEvent (true), preventing its ancestors to intercept the touch events.

    Add a transparent view over the mapview fragment:

    
        ...
             
                 
                 
                 
             
    
    

    Set touch listener for that transparent view:

        var transparentTouchPanel = view.FindViewById (Resource.Id.transparent_touch_panel);
        transparentTouchPanel.SetOnTouchListener (this);
    

    ....

    public bool OnTouch (View v, MotionEvent e) {
        switch (e.Action) {
        case MotionEventActions.Up:
            v.Parent.RequestDisallowInterceptTouchEvent (false);
            break;
        default:
            v.Parent.RequestDisallowInterceptTouchEvent (true);
            break;
        }
    
        return false;
    }
    

    I thought RequestDisallowInterceptTouchEvent could work with being invoked just once, but apparently it has to be called for EVERY touch event, that's why it has to be put inside onTouchEvent. And the parent will propagate this request to the parent's parent.

    I tried set touch event listener for fl_google_map, or for the mapFragment.getView(). Neither of them worked, so creating a transparent sibling view is a tolerable workaround for me.

    I have tried, this solution works perfectly. Check the comments under the original post if you do not believe me. I prefer this way because it does not need to create a custom SupportMapFragmet.

提交回复
热议问题