安卓:地图覆盖物标签

3
我正在构建一个MapView,希望我的自定义覆盖物在用户点击时显示它们所标记的位置名称,就像Android Maps应用程序一样。
我设置了onTap监听器和浮动TextView来保存位置名称。但我仍需要设置它,以便在用户移动地图等操作时重新绘制标签。
不过,我想知道是否有内置的方法我不知道。我认为大多数MapView的实现都有标签。
供参考,这是我到目前为止的实现:
在地图xml中:
<LinearLayout android:id="@+id/mapBubbleWrap"
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentTop="true">
    <TextView android:id="@+id/mapBubble" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:visibility="gone" 
        android:background="#ffffff" 
        android:textColor="#ff0000"/>
</LinearLayout>

在我的扩展ItemizedOverlay中:

public boolean onTap(int index) {

    this.setFocus( mOverlays.get(index) );      
    return true;
}

在我的Activity中的onFocus方法:

public void onFocusChanged( ItemizedOverlay overlay, OverlayItem item ) {
    if( item != null) {
        mapBubble.setText(item.getTitle());
        Point newPoint = mapView.getProjection().toPixels(item.getPoint(), null);
        mapBubbleWrap.setPadding(newPoint.x, newPoint.y-10, 0, 0);
        mapBubble.setVisibility(View.VISIBLE);
    }
}
1个回答

3
我认为大多数MapView实现都带有标签。
可能是这样的,但Google地图附加组件中没有内置支持它们的内容,除了你正在做的。虽然我不完全明白整个焦点问题是什么。如果我想要在用户点击时弹出一个弹出面板,我只需要在用户点击时显示一个弹出面板 - 可以参考这个项目

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接