【发布时间】:2023-04-09 06:29:01
【问题描述】:
我试图在我的 MapFragment 上实现呼吸效果动画,但由于某种原因,我无法在地图上运行多个动画。我想要实现的是这样的:
并且圈子正在逐渐扩大并逐渐消失。现在我的动画正在这样做:
这不是我想要的。当前代码(如果我使用处理程序取消注释 2 个块)仅执行一个动画,其余形状保持静止。编辑我发现了发生了什么-“startAnimation”方法正在覆盖当前动画。现在我想知道是否有办法避免这种覆盖?有什么想法吗?:
这是我的代码:
@Override
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
//Add smallest image drawable overlay
mDotMarkerBitmap = generateBitmapFromDrawable(R.drawable.circle_drawable);
groundOverlay = mMap.addGroundOverlay(new GroundOverlayOptions()
.image(BitmapDescriptorFactory.fromBitmap(mDotMarkerBitmap))
.position(xDesign, 100));
groundAnimation = new RadiusAnimation(groundOverlay);
groundAnimation.setRepeatCount(Animation.INFINITE);
groundAnimation.setRepeatMode(Animation.RESTART);
groundAnimation.setDuration(2000);
mapFragment.getView().startAnimation(groundAnimation); // MapView where i show my map
//TODO Fix the animation tomorrow
//Add medium size image drawable overlay
// new Handler().postDelayed(new Runnable() {
// @Override
// public void run() {
// // your code here
// mDotMarkerBitmap = generateBitmapFromDrawable(R.drawable.circle_drawable2);
// groundOverlay = mMap.addGroundOverlay(new GroundOverlayOptions()
// .image(BitmapDescriptorFactory.fromBitmap(mDotMarkerBitmap))
// .position(xDesign, 100));
// groundAnimation = new RadiusAnimation(groundOverlay);
// groundAnimation.setRepeatCount(Animation.INFINITE);
// groundAnimation.setRepeatMode(Animation.RESTART);
// groundAnimation.setDuration(10000);
// mapFragment.getView().startAnimation(groundAnimation); // MapView where i show my map
// }
// }, 1000/* 1sec delay */);
//
////Add smallest size image drawable overlay
// new Handler().postDelayed(new Runnable()
// {
// @Override
// public void run()
// {
// // your code here
// mDotMarkerBitmap = generateBitmapFromDrawable(R.drawable.circle_drawable3);
// groundOverlay = mMap.addGroundOverlay(new GroundOverlayOptions()
// .image(BitmapDescriptorFactory.fromBitmap(mDotMarkerBitmap))
// .position(xDesign, 100));
// groundAnimation = new RadiusAnimation(groundOverlay);
// groundAnimation.setRepeatCount(Animation.INFINITE);
// groundAnimation.setRepeatMode(Animation.RESTART);
// groundAnimation.setDuration(2000);
// mapFragment.getView().startAnimation(groundAnimation); // MapView where i show my map
// }
// }, 1000/* 1sec delay */);
mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(xDesign, 15));
}
circle_drawable.xml(circle_drawable2 和 3 除了宽度和高度值相同,它们更大 60 和 90dp 以及颜色 - 蓝色和红色):
<?xml version="1.0" encoding="utf-8"?>
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<solid
android:color="#0093e8"/>
<size
android:width="30dp"
android:height="30dp"/>
</shape>
RadiusAnimation 类:
public class RadiusAnimation extends Animation {
private GroundOverlay groundOverlay;
public RadiusAnimation(GroundOverlay groundOverlay) {
this.groundOverlay = groundOverlay;
}
@Override
protected void applyTransformation(float interpolatedTime, Transformation t) {
groundOverlay.setDimensions( (100 * interpolatedTime) );
groundOverlay.setTransparency( interpolatedTime );
}
@Override
public void initialize(int width, int height, int parentWidth,int parentHeight) {
super.initialize(width, height, parentWidth, parentHeight);
}
}
【问题讨论】:
标签: android animation google-maps-markers google-maps-android-api-2 android-maps