使用Android中的ObjectAnimator在Google Maps上旋转标记

问题描述 投票:1回答:1

我指的是此代码段,以在使用ObjectAnimator的Google Maps上对标记进行动画处理。一旦方法结束,我将再次调用该方法,并从列表中为其提供新值。

public class MarkerAnimation {
static GoogleMap map;
ArrayList<LatLng> _trips = new ArrayList<>() ;
Marker _marker;
LatLngInterpolator _latLngInterpolator = new LatLngInterpolator.Spherical();

public void animateLine(ArrayList<LatLng> Trips,GoogleMap map,Marker  marker,Context current){
    _trips.addAll(Trips);
    _marker = marker;

animateMarker();
}

public void animateMarker() {
    TypeEvaluator<LatLng> typeEvaluator = new TypeEvaluator<LatLng>() {
        @Override
        public LatLng evaluate(float fraction, LatLng startValue, LatLng endValue) {
            return _latLngInterpolator.interpolate(fraction, startValue, endValue);
        }
    };
    Property<Marker, LatLng> property = Property.of(Marker.class, LatLng.class, "position");

    ObjectAnimator animator = ObjectAnimator.ofObject(_marker, property, typeEvaluator, _trips.get(0));

    //ObjectAnimator animator = ObjectAnimator.o(view, "alpha", 0.0f);
    animator.addListener(new Animator.AnimatorListener() {
        @Override
        public void onAnimationCancel(Animator animation) {
            //  animDrawable.stop();
        }

        @Override
        public void onAnimationRepeat(Animator animation) {
            //  animDrawable.stop();
        }

        @Override
        public void onAnimationStart(Animator animation) {
            //  animDrawable.stop();
        }

        @Override
        public void onAnimationEnd(Animator animation) {
            //  animDrawable.stop();
            if (_trips.size() > 1) {
                _trips.remove(0);
                animateMarker();
            }
        }
    });

    animator.setDuration(300);   
    animator.start();
}

ObjectAnimator最适合我的需求,我想知道是否可以使用它平滑旋转(汽车)标记。

android google-maps objectanimator
1个回答
0
投票

[我看到了您的代码,引起了我的注意,我有一个类似的带有价值动画设计器的代码,如果您不太麻烦,我希望您能使用objectanimator做到这一点

© www.soinside.com 2019 - 2024. All rights reserved.