【问题标题】:Reveal Map after the Location is found & Map Ready找到位置并准备好地图后显示地图
【发布时间】:2023-03-14 10:26:01
【问题描述】:

我正在尝试使用地图来实现这种加载。在创建 Google 地图并找到位置后,我尝试加载我的动画。但是位置加载在动画完成后开始。地图相机导航到用户位置后如何实现显示动画。

我没有使用启动画面。动画代码在 MapsActivity 中。

private void setupRevealBackground(){
        final int revealX = (int) (mBackgroundView.getX() + mBackgroundView.getWidth() / 2);
        final int revealY = (int) (mBackgroundView.getY() + mBackgroundView.getHeight() / 2);
        ViewTreeObserver viewTreeObserver = mBackgroundView.getViewTreeObserver();
        if (viewTreeObserver.isAlive()) {
            viewTreeObserver.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
                @Override
                public void onGlobalLayout() {
                    revealActivity(revealX, revealY);
                    mBackgroundView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
                }
            });
        }
    }

    protected void revealActivity(int x, int y) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            float finalRadius = (float) (Math.max(mBackgroundView.getWidth(), mBackgroundView.getHeight()) * 1.1);

            // create the animator for this view (the start radius is zero)
            Animator circularReveal = ViewAnimationUtils.createCircularReveal(mBackgroundView, x, y, 0, finalRadius);
            circularReveal.setDuration(400);
            circularReveal.setInterpolator(new AccelerateInterpolator());

            // make the view visible and start the animation
            circularReveal.start();
            circularReveal.addListener(new Animator.AnimatorListener() {
                @Override
                public void onAnimationStart(Animator animation) {

                }

                @Override
                public void onAnimationEnd(Animator animation) {
                    mBackgroundView.setVisibility(View.GONE);
                }

                @Override
                public void onAnimationCancel(Animator animation) {

                }

                @Override
                public void onAnimationRepeat(Animator animation) {

                }
            });
        } else {
            finish();
        }
    }

找到位置后,我正在更新位置 Preference Change Listener。

@Override
    public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
        if (key.equals(Constants.LatitudePref)) {
            Latitude = LocationResultHelper.getSavedLatitude(sharedPreferences);
            Longitude = LocationResultHelper.getSavedLongitude(sharedPreferences);
            if (mPickUpLatLng == null){
                updateMarker(new LatLng(Latitude, Longitude));
            }
        } else if (key.equals(Constants.KEY_LOCATION_UPDATES_REQUESTED)) {
            LocationRequestHelper.getRequesting(this);
        }
    }

这是我找到位置后的updateMarker方法

private void updateMarker(LatLng userLocation) {
        mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(userLocation, 16));
        setupRevealBackground();
     }

我尝试在CameraIdleListener 中添加setupRevealBackground() 方法,但从未调用该方法。

【问题讨论】:

    标签: android android-animation android-location android-maps-v2


    【解决方案1】:

    answer 所示,您可以使用OnMapLoadedCallback

    当您引用地图时设置回调。

    mMap.setOnMapLoadedCallback(this);
    

    onMapLoaded 事件触发时拍摄快照。

    @Override
    public void onMapLoaded() {
        // Here you can display your map with animation
    }
    

    【讨论】:

    • 我试过了,但它会在加载地图时开始显示动画。
    • 你的意思是地图加载完成还是加载中?
    • 当地图已经定位到用户位置时。
    • 这不是你想要达到的目标吗?
    • 地图最初在默认的谷歌地图区域加载,然后在找到时重定向到用户的位置。
    猜你喜欢
    • 2014-11-19
    • 2011-10-03
    • 2017-10-04
    • 2011-10-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多