答案 0 :(得分:1)
这是一个循环方法的例子-首先是录音,然后是代码。
这里的半径增长是线性的,但是显然在您的示例中是一个不同的函数(它随着扩展而变慢),因此您需要使用它。
public void pulseCircleTest() {
// arbitrary point
LatLng pt = new LatLng(39.171755, -86.510632);
// move map to point of interest
CameraPosition cp = CameraPosition.builder().target(pt).zoom(8.0F).build();
mMap.animateCamera(CameraUpdateFactory.newCameraPosition(cp));
// create a circle and start animation
int color = Color.BLUE;
float initialRadius = 10;
float maxRadius = 20000f;
CircleOptions co = new CircleOptions().center(pt).radius(initialRadius).strokeColor(color).fillColor(color).strokeWidth(1.0f);
Circle c = mMap.addCircle(co);
Circle c2 = mMap.addCircle(co);
final Handler h = new Handler();
h.postDelayed(new Fader(h,c, initialRadius, maxRadius, Color.BLUE, co), 300);
h.postDelayed(new Fader(h,c2, initialRadius, maxRadius, Color.BLUE, co), 750);
}
private class Fader implements Runnable {
private float radius, initialRadius, maxRadius;
private int baseColor, color, initialColor;
private Handler h;
private Circle c;
private float radiusJump = 400;
int numIncrements, alphaIncrement;
private CircleOptions co;
public Fader(Handler h, Circle c, float initialRadius, float maxRadius, int initialColor, CircleOptions co) {
this.initialRadius = initialRadius;
this.initialColor = initialColor;
this.maxRadius = maxRadius;
this.h = h;
this.c = c;
this.co = co;
reset();
}
private void reset() {
radius = initialRadius;
this.color = initialColor;
this.baseColor = initialColor;
numIncrements = (int)((maxRadius - initialRadius) / radiusJump);
alphaIncrement = 0x100 / numIncrements;
if (alphaIncrement <= 0) alphaIncrement = 1;
}
public void run() {
int alpha = Color.alpha(color);
radius = radius + radiusJump;
c.setRadius(radius);
alpha -= alphaIncrement;
color = Color.argb(alpha, Color.red(baseColor), Color.green(baseColor), Color.blue(baseColor));
c.setFillColor(color);
c.setStrokeColor(color);
if (radius < maxRadius) {
h.postDelayed(this, 25);
} else {
c.remove();
reset();
c = mMap.addCircle(co);
h.postDelayed(this, 2000);
}
//done
}
}
答案 1 :(得分:0)
注意::这不是正确的解决方案,而只是解决方法。
在您的布局中,以Google地图片段和中央的ImageView
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<fragment
android:id="@+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:src="@drawable/ic_customerlocation" />
</RelativeLayout>
现在获取所需动画的gif图像,然后使用ImageView
或其他方式将gif图像加载到Glide
中
如果您想知道用户移动地图的位置,则可以使用onCameraIdle()
方法来获取新位置
@Override
public void onCameraIdle() {
if (mGoogleMap != null ) {
CameraPosition cameraPosition = mGoogleMap.getCameraPosition();
LatLng latLng = cameraPosition.target;
}
}