Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/google-maps/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android ScrollView中的MapFragment_Android_Google Maps_Android Mapview_Google Play Services - Fatal编程技术网

Android ScrollView中的MapFragment

Android ScrollView中的MapFragment,android,google-maps,android-mapview,google-play-services,Android,Google Maps,Android Mapview,Google Play Services,我在滚动视图中有一个新的s。实际上,它是一个SupportMapFragment,但无论如何。这是可行的,但有两个问题: 滚动时,会留下一个黑色的遮罩。黑色正好覆盖了地图所在的区域,除了+/-缩放按钮所在的孔。请参见下面的屏幕截图。这是安卓4.0上的 当用户与地图交互时,视图不使用requestDisallowerceptouchevent(),以防止ScrollView拦截触摸,因此如果您尝试在地图中垂直平移,它只会滚动包含ScrollView的内容。理论上,我可以派生一个视图类MapView

我在
滚动视图中有一个新的s。实际上,它是一个
SupportMapFragment
,但无论如何。这是可行的,但有两个问题:

  • 滚动时,会留下一个黑色的遮罩。黑色正好覆盖了地图所在的区域,除了+/-缩放按钮所在的孔。请参见下面的屏幕截图。这是安卓4.0上的

  • 当用户与地图交互时,视图不使用
    requestDisallowerceptouchevent()
    ,以防止
    ScrollView
    拦截触摸,因此如果您尝试在地图中垂直平移,它只会滚动包含
    ScrollView
    的内容。理论上,我可以派生一个视图类
    MapView
    ,并添加该功能,但我如何才能让
    MapFragment
    使用自定义的
    MapView
    ,而不是标准的


  • 在mapview片段上应用透明图像似乎可以解决问题。这不是最漂亮的,但似乎很管用。下面是一个XML片段,它显示了以下内容:

    <RelativeLayout
            android:id="@+id/relativeLayout1"
            android:layout_width="match_parent"
            android:layout_height="300dp" >
    
            <fragment
                android:id="@+id/map"
                android:name="com.google.android.gms.maps.MapFragment"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"/>
    
            <ImageView
                android:id="@+id/imageView123"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:src="@drawable/temp_transparent" />         
    </RelativeLayout>
    
    
    
    这可能与中的问题根源相同。这里的解决方案是使用一个透明框架,它比透明图像轻一点。

    对于问题的第二部分,您可以从SupportMapFragment派生一个片段类,并在布局中使用它。然后,您可以在那里覆盖并实例化自定义地图视图


    如果这不起作用,您可以始终创建自己的片段——然后您只需要自己调用所有生命周期方法(onCreate、onResume等)。有一些更详细的信息。

    对我来说,添加一个透明的ImageView无助于完全移除黑色遮罩。在滚动时,地图的顶部和底部仍然显示黑色蒙版

    因此,解决方案,我发现在一个小的变化。 我补充说,

    我的地图片段,因为它是垂直滚动视图。所以我的布局现在看起来是这样的:

    <RelativeLayout
        android:id="@+id/map_layout"
        android:layout_width="match_parent"
        android:layout_height="300dp">
    
        <fragment
            android:id="@+id/mapview"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_marginTop="-100dp"
            android:layout_marginBottom="-100dp"
            android:name="com.google.android.gms.maps.MapFragment"/>
    
        <ImageView
            android:id="@+id/transparent_image"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:src="@color/transparent" />
    
    </RelativeLayout>   
    

    这对我有用。希望对您有所帮助。

    我使用了这种结构,并克服了这个问题

    我使用了一个容器视图来查看maps片段

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent">
    
        <LinearLayout
            android:orientation="vertical"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">
    
            <TextView
                android:text="Another elements in scroll view1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" />
    
    
            <com.erolsoftware.views.MyMapFragmentContainer
                android:orientation="vertical"
                android:layout_width="match_parent"
                android:layout_height="250dp">
    
                <fragment
                    xmlns:android="http://schemas.android.com/apk/res/android"
                    xmlns:tools="http://schemas.android.com/tools"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:id="@+id/eventMap"
                    tools:context="com.erolsoftware.eventapp.EventDetails"
                    android:name="com.google.android.gms.maps.SupportMapFragment"/>
    
            </com.erolsoftware.views.MyMapFragmentContainer>
    
            <TextView
                android:text="Another elements in scroll view2"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" />
    
    
    
        </LinearLayout>
    
    
    
    
    </ScrollView>
    

    经过大量研发后完成:

    fragment\u one.xml应该如下所示:

    <?xml version="1.0" encoding="utf-8"?>
    <ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/scrollViewParent"
        android:orientation="vertical" >
    
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical" >
    
            <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="400dip" >
    
                <com.google.android.gms.maps.MapView
                    android:id="@+id/mapView"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent" />
    
                <View
                    android:id="@+id/customView"
                    android:layout_width="fill_parent"
                    android:layout_height="fill_parent"
                    android:background="@android:color/transparent" />
            </RelativeLayout>
    
            <!-- Your other elements are here -->
    
        </LinearLayout>
    
    </ScrollView>
    
    private GoogleMap mMap;
    private MapView mapView;
    private UiSettings mUiSettings;
    private View customView
    
    onCreateView


    无需与CustomScrollView和透明布局文件斗争。只需使用较轻版本的谷歌地图,您的问题就会得到解决

      map:liteMode="true"
    

    在布局文件的地图片段中添加上述属性。这个问题将得到解决

    “我在ScrollView中有一个新的MapFragments”--如果这工作正常,我会感到惊讶。“我怎样才能让MapFragment使用我的自定义地图视图而不是标准地图视图?”--你不能,阿飞。您必须创建自己的片段来承载
    MapView
    。我也面临同样的问题,但我在片段中使用原始MapView。同样的问题,当在ScrollView或ViewPager中滚动时,黑色遮罩被留下。在我的Nexus S(Android 4.1.2)上,我没有遇到这个问题。然而,在我测试过的所有Android 2.2-2.3设备上,我都遇到了完全相同的问题。我可以确认这是有效的(尽管屏幕的某些部分仍然闪烁。我最终使用了一个框架布局作为父级,并使用了一个带有
    Android:background=“@Android:color/transparent”的普通
    关于透明视图。谢谢伙计,我指的是这么多不起作用的东西,但是你的简单和灰色。当使用MapView而不是MapFragment时,有没有类似的解决方法?@Abdul Wahab:是的。我这样设置的,我可以点击地图上的标记。谢谢亲爱的,它的帮助谢谢,这解决了这两个问题,这就是为什么应该实际接受它的原因ted作为答案。mGoogleMap.getUiSettings().setMyLocationButtonneEnabled(true)不适用于此解决方案。我坐在嵌套的小部件结构中增加了复杂性。但我最终通过使用您的解决方案找到了出路。(我的滚动视图只能通过使用view.getParent()访问)就像《魅力》一样,当我的案例中投票率最高的答案失败时,它帮助了我。谢谢。我认为更快、更轻、更好的答案
    <?xml version="1.0" encoding="utf-8"?>
    <ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/scrollViewParent"
        android:orientation="vertical" >
    
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical" >
    
            <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="400dip" >
    
                <com.google.android.gms.maps.MapView
                    android:id="@+id/mapView"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent" />
    
                <View
                    android:id="@+id/customView"
                    android:layout_width="fill_parent"
                    android:layout_height="fill_parent"
                    android:background="@android:color/transparent" />
            </RelativeLayout>
    
            <!-- Your other elements are here -->
    
        </LinearLayout>
    
    </ScrollView>
    
    private GoogleMap mMap;
    private MapView mapView;
    private UiSettings mUiSettings;
    private View customView
    
    mapView = (MapView) rootView.findViewById(R.id.mapView);
    mapView.onCreate(savedInstanceState);
    
    if (mapView != null) {
       mMap = mapView.getMap();
       mMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
       mUiSettings = mMap.getUiSettings();
       mMap.setMyLocationEnabled(true);
       mUiSettings.setCompassEnabled(true); 
       mUiSettings.setMyLocationButtonEnabled(false);
    }
    
    
    scrollViewParent = (ScrollView)rootView.findViewById(R.id.scrollViewParent);
    customView = (View)rootView.findViewById(R.id.customView);
    
    customView.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.
                            scrollViewParent.requestDisallowInterceptTouchEvent(true);
                            // Disable touch on transparent view
                            return false;
    
                        case MotionEvent.ACTION_UP:
                            // Allow ScrollView to intercept touch events.
                            scrollViewParent.requestDisallowInterceptTouchEvent(false);
                            return true;
    
                        case MotionEvent.ACTION_MOVE:
                            scrollViewParent.requestDisallowInterceptTouchEvent(true);
                            return false;
    
                        default:
                            return true;
                    }
                }
            });
    
    <ScrollView
                android:layout_width="match_parent"
        ::
        ::
        ::
          <FrameLayout
                android:id="@+id/map_add_business_one_rl"
                android:layout_width="match_parent"
                android:layout_height="100dp"
             >
                            <fragment
    
                                android:id="@+id/map"
                                android:name="com.google.android.gms.maps.SupportMapFragment"
                                android:layout_width="match_parent"
                                android:layout_height="match_parent"
                                android:layout_marginTop="-100dp"
                                android:layout_marginBottom="-100dp"
    
                                />
    
            </FrameLayout>
    
        ::
        ::
        ::
         </ScrollView>
    
      map:liteMode="true"