Android Google Maps v2:动画标记大小 [英] Android Google Maps v2: animate marker size

查看:90
本文介绍了Android Google Maps v2:动画标记大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试为添加到地图中的标记设置动画,基本上,我希望标记增加。我看不到标记实际视图的任何方法,因此我认为我无法使用标准的Android动画技术(例如 ObjectAnimator )。

I'm trying to animate the size of a marker as it is added to a map, basically I want the marker to grow. I can't see any way of getting to the actual view for the marker so I don't think I can use the standard Android animation techniques (e.g. ObjectAnimator).

我看到的唯一方法是实现自己的动画并使用 setIcon 方法更改标记图标。

The only way I can see to do this would be to implement my own animation and use the setIcon method to change the marker icon.

还有其他更好的方法吗?

Is there any other and ideally better way of doing this?

我正在从事Xamarin,但可以在必要时移植Java代码。

I'm working in Xamarin but can port Java code if necessary.

推荐答案

您可以尝试使用类似的方法

You may try something like this

final Marker marker = map.addMarker(new MarkerOptions().position(new LatLng(0, 0)).title("Marker"));
final Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.ic_temperature_kelvin_black_48dp);
final Bitmap target = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Bitmap.Config.ARGB_8888);
final Canvas canvas = new Canvas(target);
ValueAnimator animator = ValueAnimator.ofFloat(0, 1);
animator.setDuration(500);
animator.setStartDelay(1000);
final Rect originalRect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());
final RectF scaledRect = new RectF();
animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
    @Override
    public void onAnimationUpdate(ValueAnimator animation) {
        float scale = (float) animation.getAnimatedValue();
        scaledRect.set(0, 0, originalRect.right * scale, originalRect.bottom * scale);
        canvas.drawBitmap(bitmap, originalRect, scaledRect, null);
        marker.setIcon(BitmapDescriptorFactory.fromBitmap(target));
    }
});
animator.start();

这篇关于Android Google Maps v2:动画标记大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆