【问题标题】:how to change state of any overlayItem on googlemap?如何更改谷歌地图上覆盖项目的状态?
【发布时间】:2010-02-05 16:08:57
【问题描述】:

我能够在 Googlemap 上显示多个叠加项,现在我想更改任何特定叠加项的图标(以显示它是当前选定的事件)。我想通过导航按钮(下一个、上一个)来完成,就像在谷歌地图上一样。

我正在使用 StateListDrawable 来显示 OverlayItems 的图标。

图标文件是

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
 <item android:state_selected="true" android:drawable="@drawable/selected_icon"/>
 <item android:drawable="@drawable/unselected_icon"/>
</selector>

OverlayItem的getMarker方法代码如下。

@Override
public android.graphics.drawable.Drawable getMarker(int stateBitset){
    Drawable icon;              
    icon = this.mapActivity.getResources().getDrawable(R.drawable.film_icon);
    icon.setBounds(0, 0, icon.getIntrinsicWidth(), icon.getIntrinsicHeight());
    return icon;
}

现在我的问题是,当用户单击其中一个导航键时,如何更改地图上任何覆盖项/图标的状态?

非常感谢任何帮助。

【问题讨论】:

    标签: android google-maps map overlay


    【解决方案1】:

    您是否尝试使用 setState(int id) 方法?

    基本上,您可以使用为 StateListDrawable 定义为 XML 属性的预定义状态并根据其 ID(即 android.R.attr.state_active)设置状态,或者您可以使用 addState(int[] stateSet 添加自己的状态, Drawable drawable)。

    我自己没有尝试过,所以不能断定它有效。

    【讨论】:

    • 是的,这就是我在点击导航键时所做的。我试过 setFocus(overlayItem) 也试过 setMarker(Drawable),但没有运气:(
    猜你喜欢
    • 2019-09-09
    • 1970-01-01
    • 1970-01-01
    • 2018-10-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多