how to set google map fragment inside scroll view

后端 未结 8 940
北海茫月
北海茫月 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条回答
  •  渐次进展
    2020-11-29 00:22

    Update

    @Alok Nair's answer is very good however, the .getMap() method no longer works from android 9.2 onwards. Change the getMap method to .getMapAsync and add code in the onMapReady method

    Updated Solution, that works in Fragments

    if (gMap == null)
            {
              getChildFragmentManager().findFragmentById(R.id.map);
                SupportMapFragment mapFragment = (WorkaroundMapFragment) getChildFragmentManager().findFragmentById(R.id.map);
                mapFragment.getMapAsync(new OnMapReadyCallback()
                {
                    @Override
                    public void onMapReady(GoogleMap googleMap)
                    {
                        gMap = googleMap;
                        gMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
                        gMap.getUiSettings().setZoomControlsEnabled(true);
    
                        mScrollView = mView.findViewById(R.id.advertScrollView); //parent scrollview in xml, give your scrollview id value
                        ((WorkaroundMapFragment) getChildFragmentManager().findFragmentById(R.id.map))
                                .setListener(new WorkaroundMapFragment.OnTouchListener()
                                {
                                    @Override
                                    public void onTouch()
                                    {
                                        mScrollView.requestDisallowInterceptTouchEvent(true);
                                    }
                                });
                    }
                });
            }
    

提交回复
热议问题