Android v2 MapFragment trembles when scrolling in Scrollview

I am using SupportMapFragment to display a static map in a ScrollView. I don’t like to move / scale the map, just indicating where the place is.

When I scroll the map up, the map shakes inside its borders, it feels pretty laggy. My question is how to remove this backlog or how to use the static version of v2 api map.

This is my layout:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_margin="@dimen/margin_half" android:background="@color/white" android:orientation="vertical" > ... <fragment android:id="@+id/fragmentMap" android:name="com.google.android.gms.maps.SupportMapFragment" android:layout_width="match_parent" android:layout_height="300dp" android:layout_alignParentLeft="true" android:layout_below="@id/viewDivider" android:layout_margin="@dimen/margin_half" /> <View android:layout_width="match_parent" android:layout_height="300dp" android:layout_alignBottom="@id/fragmentMap" android:layout_alignLeft="@id/fragmentMap" android:layout_alignRight="@id/fragmentMap" android:layout_alignTop="@id/fragmentMap" android:background="@android:color/transparent" /> ... </RelativeLayout> 

This is not related to MapFragment in ScrollView , although I used this trick to remove black trim on older devices, as you can see with a transparent view,

I also turned off all gestures and the ability to click on the map:

 getMap().getUiSettings().setAllGesturesEnabled(false); getMap().getUiSettings().setZoomControlsEnabled(false); getMap().getUiSettings().setMyLocationButtonEnabled(false); ... mapView.setClickable(false); mapView.setFocusable(false); mapView.setDuplicateParentStateEnabled(false); 
+2
android android-maps-v2 scrollview
Jul 24 '13 at 9:11
source share
2 answers

The new release of Google Play Google services has added the snapshot method to get the bitmap of the currenrt map that can be displayed. So interaction is impossible, but when renting a card, it no longer trembles.

use

 GoogleMap.snapshot (GoogleMap.SnapshotReadyCallback callback) 

and implement SnapshotReadyCallback. Once the snapshot is delivered, replace MapFragment with an ImageView containing the snapshot.

This example works very well in the onResume method:

 @Override public void onResume() { super.onResume(); notifyDataChanged(); final ViewTreeObserver viewTreeObserver = fragmentMap.getView() .getViewTreeObserver(); if (viewTreeObserver.isAlive()) { viewTreeObserver .addOnGlobalLayoutListener(new OnGlobalLayoutListener() { @Override public void onGlobalLayout() { onMesuredMap(this); } }); } } private void onMesuredMap(OnGlobalLayoutListener listener) { if (fragmentMap.getView().getWidth() != 0 && fragmentMap.getView().getHeight() != 0) { fragmentMap.getView().getViewTreeObserver() .removeOnGlobalLayoutListener(listener); makeSnapShot(); } } private void makeSnapShot() { Runnable action = new Runnable() { @Override public void run() { fragmentMap.getMap().snapshot(new SnapshotReadyCallback() { @Override public void onSnapshotReady(Bitmap arg0) { imageViewStaticMap.setImageBitmap(arg0); removeMapFragment(); } }); } }; //litle hack to make sure that the map is loaded for sure fragmentMap.getView().postDelayed(action, 1500); } private void removeMapFragment() { if (fragmentMap.isVisible()) { getChildFragmentManager() .beginTransaction() .remove(fragmentMap) .commit(); } } 

Sidenote: To use the new version, run the Android SDK Manager update, and when using maven, run maven-android-sdk-deployer with:

 mvn install -fae 
+1
Aug 13 '13 at 2:55
source share

Try using this class, it should look better, at least when scrolling left and left in our scrollview:

 public class TransparentSupportMapFragment extends SupportMapFragment { public TransparentSupportMapFragment() { super(); } @Override public View onCreateView(LayoutInflater inflater, ViewGroup view, Bundle savedInstance) { View layout = super.onCreateView(inflater, view, savedInstance); FrameLayout frameLayout = new FrameLayout(getActivity()); frameLayout.setBackgroundColor(getResources().getColor(android.R.color.transparent)); ((ViewGroup) layout).addView(frameLayout, new ViewGroup.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)); return layout; } } 
0
Jul 24. '13 at 9:12
source share



All Articles