【问题标题】:Google Maps in android app integration not dragging/moving smoothlyandroid 应用程序集成中的谷歌地图不能顺利拖动/移动
【发布时间】:2020-06-17 15:09:54
【问题描述】:

在我的 android 应用程序中,我正在将 google map 动态集成到 bottomsheetfragment,它正在顺利加载,但是当我执行任何操作(如用手指移动地图、拖动标记)时,它无法顺利工作,我不得不点击多次才能向右或向左移动,垂直移动没有发生,请帮忙。

// this code is to load fragment inside bottom sheet dialog fragment
if (mapFragment == null) {
                mapFragment = SupportMapFragment.newInstance();
                mapFragment.getMapAsync(this);
            }
            FragmentTransaction transaction = activity
                    .getSupportFragmentManager()
                    .findFragmentByTag(BottomDialogCommon.TAG)
                    .getChildFragmentManager()
                    .beginTransaction();
            // R.id.map is a layout
            transaction.replace(R.id.map, mapFragment).commit();

 @Override
        public void onMapReady(GoogleMap googleMap) {
            //mMap = googleMap;

            // Add a marker in Sydney and move the camera
            LatLng sydney = new LatLng(26.47674, 80.334466);
            googleMap.addMarker(new MarkerOptions().position(sydney).draggable(true).title("Marker in Sydney"));
            googleMap.moveCamera(CameraUpdateFactory.newLatLng(sydney));
            googleMap.animateCamera( CameraUpdateFactory.zoomTo( 17.0f ) );
            // Enable the zoom controls for the map
            googleMap.getUiSettings().setZoomControlsEnabled(true);
            googleMap.getUiSettings().setScrollGesturesEnabled(true);
            googleMap.getUiSettings().setZoomGesturesEnabled(true);...

【问题讨论】:

    标签: android google-maps


    【解决方案1】:

    这是因为默认情况下底部的工作表片段是可取消的。拖动地图会导致片段移动。因此,在显示地图时,将dialog.isCancellable 设置为false 并添加自定义取消按钮。

    【讨论】:

    • 我已经设置cancellable为false,但是错误没有修复
    【解决方案2】:

    当您有两个或多个可移动元素相互嵌套时,就会发生这种情况。一个简单的解决方法是将android:nestedScrollingEnabled="true" 标签添加到第一个可移动元素。在您的情况下,您希望将其添加到包含您的MapFragmentbottomsheetfragment 中。

    查看我的GitHub repo 以获取以下示例。

    bottomsheetfragment.xml

    bottomsheetDialog.java

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-02-03
      • 2014-12-21
      • 2017-10-22
      • 1970-01-01
      • 2014-08-28
      • 2012-01-06
      • 2012-10-14
      • 1970-01-01
      相关资源
      最近更新 更多