gpt4 book ai didi

android - 如何在 Android 的谷歌地图上显示波纹动画?

转载 作者:塔克拉玛干 更新时间:2023-11-02 22:04:44 27 4
gpt4 key购买 nike

我正在尝试使用特定的 Lat-Lng 在 google map 上设置涟漪动画,请参阅 this这正是我想要的,我引用了上面的链接,但无法在 google map 上设置动画。

到目前为止我尝试的是-

我的 xml 代码:

<com.test.custom.RippleBackground
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/rippleLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="gone"
app:rb_color="#0099CC"
app:rb_duration="5000"
app:rb_radius="32dp"
app:rb_rippleAmount="4"
app:rb_scale="6" >

<ImageView
android:id="@+id/imgMapProfile"
android:layout_width="64dp"
android:layout_height="64dp"
android:layout_centerInParent="true"
android:src="@drawable/ic_profile_active" />
</com.test.custom.RippleBackground>

我在谷歌地图上放置波纹的 Java 代码:

 LatLng currentAddressLatLong;              
currentAddressLatLong = new LatLng(gps.getLatitude(), gps.getLongitude());

RippleBackground rippleLayout=(RippleBackground)findViewById(R.id.rippleLayout);
rippleLayout.setVisibility(View.VISIBLE);
ImageView imgMapProfile=(ImageView)findViewById(R.id.imgMapProfile);

Bitmap markerUserBitmap = Comman.createDrawableFromView(NearByActivity.this, rippleLayout);
googleMap.addMarker(new MarkerOptions().position(currentAddressLatLong).icon(BitmapDescriptorFactory.fromBitmap(markerUserBitmap)));
googleMap.moveCamera(CameraUpdateFactory.newLatLng(currentAddressLatLong));
googleMap.animateCamera(CameraUpdateFactory.zoomTo(11));

rippleLayout.startRippleAnimation();

// Convert a view to bitmap function
public static Bitmap createDrawableFromView(Context context, View view)
{
DisplayMetrics displayMetrics = new DisplayMetrics();
((Activity)context).getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
view.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
view.measure(displayMetrics.widthPixels, displayMetrics.heightPixels);
view.layout(0, 0, displayMetrics.widthPixels, displayMetrics.heightPixels);
view.buildDrawingCache();
Bitmap bitmap = Bitmap.createBitmap(view.getMeasuredWidth(), view.getMeasuredHeight(), Bitmap.Config.ARGB_8888);

Canvas canvas = new Canvas(bitmap);
view.draw(canvas);

return bitmap;
}

但是位图没有动画。请帮忙。非常感谢。

最佳答案

对于想要像这样在谷歌地图中创建波纹背景的每个人 enter image description here

  1. 创建 3 个具有相同圆圈的 GroundOverlay。将图片放入drawable文件夹
  2. 创造值(value)动画师
  3. 定期在 ValueAnimator 中发送 3 个 GroundOverlay下面的代码:在 onCreateView 内部
 new Handler().postDelayed(new Runnable() {
@Override public void run() {final GroundOverlay groundOverlay11=googleMap.addGroundOverlay(new
GroundOverlayOptions()
.position(latLng, 2000)
.transparency(0.5f)
.image(BitmapDescriptorFactory.fromResource(R.drawable.krug)));
OverLay(groundOverlay11);
}
}, 0);
    new Handler().postDelayed(new Runnable() {
@Override
public void run() {
final GroundOverlay groundOverlay1=googleMap.addGroundOverlay(new GroundOverlayOptions()
.position(latLng, 2000)
.transparency(0.5f)
.image(BitmapDescriptorFactory.fromResource(R.drawable.krug)));
OverLay(groundOverlay1);
}
}, 4000);

new Handler().postDelayed(new Runnable() {
@Override
public void run() {
final GroundOverlay groundOverlay2=googleMap.addGroundOverlay(new GroundOverlayOptions()
.position(latLng, 2000)
.transparency(0.5f)
.image(BitmapDescriptorFactory.fromResource(R.drawable.krug)));
OverLay(groundOverlay2);
}
}, 8000);

和覆盖类:

public void OverLay(final GroundOverlay groundOverlay){
vAnimator = ValueAnimator.ofInt(0, 2000);
int r=99999;
vAnimator.setRepeatCount(r);
//vAnimator.setIntValues(0, 500);
vAnimator.setDuration(12000);
vAnimator.setEvaluator(new IntEvaluator());
vAnimator.setInterpolator(new LinearInterpolator());
vAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator valueAnimator) {
float animatedFraction = valueAnimator.getAnimatedFraction();
Integer i = (Integer) valueAnimator.getAnimatedValue();
groundOverlay.setDimensions(i);
}
});
vAnimator.start();
}

关于android - 如何在 Android 的谷歌地图上显示波纹动画?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33819986/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com