I have one of the new MapFragment
s in a ScrollView
. Actually it's a SupportMapFragment
, but anyway. It works, but there are two problems:
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.
The view doesn't use
requestDisallowInterceptTouchEvent()
when the user interacts with the map to prevent theScrollView
intercepting touches, so if you try to pan vertically in the map, it just scrolls the containingScrollView
. I could theoretically derive a view classMapView
and add that functionality, but how can I getMapFragment
to use my customisedMapView
instead of the standard one?
For the second part of the question - you can derive a fragment class from SupportMapFragment, and use that in your layout instead. You can then override Fragment#onCreateView, and instantiate your custom MapView there.
If that does not work, you can always create your own fragment - then you just need to take care of calling all the lifecycle methods yourself (onCreate, onResume, etc). This answer has some more details.
This probably has its roots in the same place at causes the problem in this question. The solution there is to use a transparent frame, which is a little lighter weight than a transparent image.
Done after lots of R&D:
fragment_one.xml should looks like:
Your Java class of FragmentOne.java looks like:
onCreateView
I used this structures and I overcame the problem.
I used a container view for maps fragment.
The container class:
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: