【问题标题】:Draw an always centered overlay on MapView in Android在 Android 中的 MapView 上绘制始终居中的叠加层
【发布时间】:2011-09-05 03:01:22
【问题描述】:

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

我要解决的方法是使用 Overlay 的 onTouchEvent 和 MotionEvent.Move 移动覆盖的位置。

有更好的方法吗?

【问题讨论】:

    标签: android overlay android-mapview


    【解决方案1】:

    您应该能够使用包含 MapView 和 ImageView 的 RelativeLayout 来完成此操作,以用于居中的图像。这是一些示例 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 示例。

    【讨论】:

    • 谢谢,我会检查一下,然后我可以将 getcenter 传回 ImageView,这样图像就会知道我实际居中的位置,回家后会先给出它。跨度>
    • kaizenx,如果要获取地图的中心点,则必须使用 mapView.getMapCenter() 方法。
    猜你喜欢
    • 1970-01-01
    • 2023-03-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-02-25
    相关资源
    最近更新 更多