Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MapFragment in ScrollView

I have one of the new MapFragments in a ScrollView. Actually it's a SupportMapFragment, but anyway. It works, but there are two problems:

  1. When scrolled, it leaves a black mask behind. The black covers exactly the area where the map was, except for a hole where the +/- zoom buttons were. See screenshot below. This is on Android 4.0.

  2. The view doesn't use requestDisallowInterceptTouchEvent() when the user interacts with the map to prevent the ScrollView intercepting touches, so if you try to pan vertically in the map, it just scrolls the containing ScrollView. I could theoretically derive a view class MapView and add that functionality, but how can I get MapFragment to use my customised MapView instead of the standard one?

Partial screenshot of scrolling issue

like image 671
Timmmm Avatar asked Dec 06 '12 15:12

Timmmm


People also ask

What is MapFragment?

public class MapFragment extends Fragment. A Map component in an app. This fragment is the simplest way to place a map in an application. It's a wrapper around a view of a map to automatically handle the necessary life cycle needs.

Is ScrollView a Viewgroup?

In Android, a ScrollView is a view group that is used to make vertically scrollable views. A scroll view contains a single direct child only. In order to place multiple views in the scroll view, one needs to make a view group(like LinearLayout) as a direct child and then we can define many views inside it.

What is a mapview?

A View which displays a map (with data obtained from the Google Maps service). When focused, it will capture keypresses and touch gestures to move the map.

What is the use of ScrollView in Android Studio?

A view group that allows the view hierarchy placed within it to be scrolled. Scroll view may have only one direct child placed within it. To add multiple views within the scroll view, make the direct child you add a view group, for example LinearLayout , and place additional views within that LinearLayout.


1 Answers

Applying a transparent image over the mapview fragment seems to resolve the issue. It's not the prettiest, but it seems to work. Here's an XML snippet that shows this:

<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> 
like image 146
walnut_head Avatar answered Oct 05 '22 14:10

walnut_head