要添加自定义弹窗和标记样式,您需要执行以下步骤:

  1. 创建自定义布局文件(例如,'my_popup_layout.xml'),并在其中定义您想要的弹窗样式。例如:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:padding="10dp"
    android:background="@drawable/my_popup_background">

    <TextView
        android:id="@+id/popup_title"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="This is a custom popup title"
        android:textColor="#FFFFFF"
        android:textSize="16sp"
        android:textStyle="bold" />

    <TextView
        android:id="@+id/popup_description"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/popup_title"
        android:text="This is a custom popup description"
        android:textColor="#FFFFFF"
        android:textSize="14sp" />

</RelativeLayout>
  1. 创建自定义标记样式(例如,'my_marker_icon.png')并将其保存在drawable文件夹中。

  2. 在您的代码中,使用以下代码创建一个自定义标记:

Drawable myCustomMarker = getResources().getDrawable(R.drawable.my_marker_icon);
myCustomMarker.setBounds(0, 0, myCustomMarker.getIntrinsicWidth(), myCustomMarker.getIntrinsicHeight());
Marker marker = new Marker(mapView);
marker.setPosition(new GeoPoint(0, 0));
marker.setIcon(myCustomMarker);
mapView.getOverlays().add(marker);
  1. 使用以下代码在地图上添加自定义弹窗:
Marker marker = new Marker(mapView);
marker.setPosition(new GeoPoint(0, 0));
marker.setAnchor(Marker.ANCHOR_CENTER, Marker.ANCHOR_BOTTOM);
marker.setTitle('Custom Popup Title');
marker.setSnippet('Custom popup description');
marker.setInfoWindow(new MarkerInfoWindow(R.layout.my_popup_layout, mapView));
mapView.getOverlays().add(marker);

请注意,上述示例假定您已将地图视图(mapView)添加到您的布局中。

Android Osmdroid 自定义弹窗和标记样式教程

原文地址: https://www.cveoy.top/t/topic/oU9G 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录