微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

在Android中的MapView上绘制始终居中的叠加层

我想在Android的MapView中绘制一个始终居中的图像叠加层,例如定位标线

我要使用的方法是使用Overlay的onTouchEvent和
MotionEvent.Move移动叠加层的位置.

有更好的方法吗?

解决方法:

您应该能够通过RelativeLayout来实现此目的,该RelativeLayout包含一个MapView和一个ImageView用于居中图像.这是一些示例XML:

<RelativeLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="match_parent"
  android:layout_height="match_parent">
    <com.google.android.maps.MapView android:id="@+id/google_maps"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:apiKey="@string/maps_key"/>
    <ImageView android:layout_width="wrap_content"
               android:layout_height="wrap_content"
               android:layout_centerInParent="true"
               android:src="@drawable/mapcenter"/>
</RelativeLayout>

这将使图像居中,并减少了将图像居中/保持居中状态所需的任何处理.当然,还有其他方法可以使用OverlayItem进行此操作,让我知道XML方法是否不起作用,我将发布一个Overlay示例.

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐