我的活动有以下要素:
我已经定义了一个onCameraChange方法来从DB获取一些数据。
map.setOnCameraChangeListener(new GoogleMap.OnCameraChangeListener() {
@Override
public void onCameraChange(CameraPosition cameraPosition) {
SpotsMapActivity.cameraPosition = cameraPosition;
mClusterManager.onCameraChange(cameraPosition);
presenter.onMapViewUpdate(map.getCameraPosition().target, cameraPosition.zoom);
}
});
问题是片段动画不断调用onCameraChange方法。 CameraPosition没有更改其值,始终具有相同的lat / lon和zoom。
我怎样才能避免这种不断的重新调用?
编辑:
这是布局:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/map"
class="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<com.github.rahatarmanahmed.cpv.CircularProgressView xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/map_progress_view"
android:layout_width="80dp"
android:layout_height="80dp"
android:layout_centerInParent="true"
android:visibility="gone"
app:cpv_animAutostart="true"
app:cpv_indeterminate="true"
app:cpv_thickness="8px" />
<include
android:id="@+id/map_toolbar"
layout="@layout/toolbar" />
<FrameLayout
android:id="@+id/map_status_banner"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:visibility="gone"
android:layout_marginTop="-20dp"/>
<!-- <FrameLayout
android:id="@+id/main_big_card"
android:layout_width="match_parent"
android:layout_height="@dimen/card_big_height"
android:layout_alignParentBottom="true" /> -->
<android.support.design.widget.FloatingActionButton
android:id="@+id/map_my_location_custom"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@id/map_status_banner"
android:layout_alignParentRight="true"
android:layout_alignWithParentIfMissing="true"
android:layout_margin="10dp"
android:src="@drawable/ic_my_location"
app:borderWidth="0dp"
app:fabSize="normal"
app:backgroundTint="@color/white"/>
</RelativeLayout>
动画:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" >
<translate
android:fromXDelta="0"
android:fromYDelta="1000"
android:duration="1500"/>
</set>