如何在 MapView 中重新定位内置缩放控件?

发布于 2024-09-29 18:50:46 字数 156 浏览 0 评论 0原文

我需要将 MapView 的内置缩放控件放置到与默认位置不同的位置。 虽然使用 getZoomControls() 方法很容易做到,但该方法在最近的 API 版本中已被弃用。

有谁知道如何调用 getZoomControls() 来做到这一点?

I need to place built-in zoom controls of MapView into position different from the default position.
While it's easy to do using getZoomControls() method, this method is deprecated in recent API versions.

Does anyone has idea how to do this without calling getZoomControls()?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

孤君无依 2024-10-06 18:50:46

我对此有一个答案。我设法用此代码将其重新定位在左下角而不是中间

FrameLayout.LayoutParams zoomParams = new FrameLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);
ZoomControls controls = (ZoomControls) getZoomButtonsController().getZoomControls();
controls.setGravity(Gravity.LEFT);
controls.setLayoutParams(zoomParams);

I have an answer to this. I managed to reposition it with this code in the bottom left corner instead of in the middle

FrameLayout.LayoutParams zoomParams = new FrameLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);
ZoomControls controls = (ZoomControls) getZoomButtonsController().getZoomControls();
controls.setGravity(Gravity.LEFT);
controls.setLayoutParams(zoomParams);
燕归巢 2024-10-06 18:50:46

除非你正确排序你的调用,否则这个东西不会起作用。这对我有用。

    map.setBuiltInZoomControls(true);
    FrameLayout.LayoutParams zoomParams = new FrameLayout.LayoutParams(
            LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);
    ZoomControls controlls = (ZoomControls) map.getZoomButtonsController().getZoomControls();
    controlls.setGravity(Gravity.TOP);
    controlls.setLayoutParams(zoomParams);
    map.displayZoomControls(true);
    map.getController().setZoom(12);

支持@ludwigm,这是唯一对我有用的答案。谢谢。

This thing does not work unless you sequence your calls correctly. This worked for me.

    map.setBuiltInZoomControls(true);
    FrameLayout.LayoutParams zoomParams = new FrameLayout.LayoutParams(
            LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);
    ZoomControls controlls = (ZoomControls) map.getZoomButtonsController().getZoomControls();
    controlls.setGravity(Gravity.TOP);
    controlls.setLayoutParams(zoomParams);
    map.displayZoomControls(true);
    map.getController().setZoom(12);

Upvote for @ludwigm, the only answer that worked for me. Thanks.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文