Android: MapFragment not moving in animation

I have a view in which there is a MapFragment

My mainViewPanel looks something like this.

<LinearLayout android:id="@+id/main_view_panel" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_weight="0.5" android:orientation="horizontal"> <fragment android:id="@+id/map" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_weight="0.5" class="com.google.android.gms.maps.SupportMapFragment" map:cameraTargetLat="40.72" map:cameraTargetLng="-74.00" map:cameraZoom="8"/> </LinearLayout> 

My translation code is as follows

 TranslateAnimation anim = new TranslateAnimation(0, 500, 0, 0); anim.setFillAfter(true); anim.setDuration(250); mainViewPanel.startAnimation(anim); 

The rest of the scan animates, but the map remains. This is similar to the main viewport, and I see more to the right of the map, but the map itself does not visually move. Animation works great for other views like TextView.

+4
source share
2 answers

This works with newer versions of android

 mainViewPanel.animate().translationX(500); 
+3
source

This is due to the fact that a new api map is created using SurfaceView, and because of this animation this is not possible.

As a temporary patch I found is: Use the transparent view above the MapFragment . Therefore, if you animate MapFragment, it will be animated with it, and at that time the map will be invisible.

As an example:

 <RelativeLayout android:id="@+id/main_view_panel" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="horizontal"> <fragment android:id="@+id/map" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_weight="0.5" class="com.google.android.gms.maps.SupportMapFragment" map:cameraTargetLat="40.72" map:cameraTargetLng="-74.00" map:cameraZoom="8"/> <ImageView android:id="@+id/map_overlay" android:layout_width="match_parent" android:layout_height="match_parent" android:background="#00000000" /> </RelativeLayout> 

Try it. It should work.

Note. You may need to change your visibility when viewing animations. If you want the map to appear after the animation, you need to hide the overlay view and when you want to start the animation, you need to display the overlay view. But you have to make sure that the hide / unhide process will only be completed after the animation is complete.

Steps for animation :

  • Before starting the animation, display the overlay display
  • after the animation is completed, means that after some delay hides the overlay view

This works for me.

0
source

All Articles