Skip to content Skip to sidebar Skip to footer

How To Make Google Maps Scroll Properly Inside Scroll View?

I have a fragment which holds a map(view) that is inside a scroll view of my layout. Problem is that map doesn't scroll properly(difficult to scroll) up or down. The scroll view s

Solution 1:

You can add a transparent ImageView that fits the mapFragment:

           <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/imagetrans"
            android:layout_alignTop="@+id/mapfragment"
            android:layout_alignBottom="@+id/mapfragment"
            android:layout_alignEnd="@+id/mapfragment"
            android:layout_alignRight="@+id/mapfragment"
            android:layout_alignLeft="@+id/mapfragment"
            android:layout_alignStart="@+id/mapfragment"
            android:src="@color/transparent"/>

And then, when the user is touching it, disallow the scrollView:

finalScrollViewscroll= (ScrollView) findViewById(R.id.scroll);
ImageViewtransparent= (ImageView)findViewById(R.id.imagetrans);

transparent.setOnTouchListener(newView.OnTouchListener() {
        @OverridepublicbooleanonTouch(View v, MotionEvent event) {
            intaction= event.getAction();
            switch (action) {
                case MotionEvent.ACTION_DOWN:
                    // Disallow ScrollView to intercept touch events.
                    scroll.requestDisallowInterceptTouchEvent(true);
                    // Disable touch on transparent viewreturnfalse;

                case MotionEvent.ACTION_UP:
                    // Allow ScrollView to intercept touch events.
                    scroll.requestDisallowInterceptTouchEvent(false);
                    returntrue;

                case MotionEvent.ACTION_MOVE:
                    scroll.requestDisallowInterceptTouchEvent(true);
                    returnfalse;

                default:
                    returntrue;
            }
        }
    });

This way, only when the user touches the ImageView, the map will respond to touching events. The rest of the time, the ScrollView will respond.

Solution 2:

Post a Comment for "How To Make Google Maps Scroll Properly Inside Scroll View?"