gpt4 book ai didi

Android:自定义工具提示 Google map 中的按钮单击事件

转载 作者:搜寻专家 更新时间:2023-11-01 08:50:36 26 4
gpt4 key购买 nike

我正在尝试为我在 Android 平台上的 Google map 上的标记制作自定义工具提示。

我尝试了一些东西,这就是我现在拥有的。

充气类:

private class InfoHandler implements GoogleMap.InfoWindowAdapter, View.OnClickListener {

@Override
public View getInfoWindow(Marker marker) {
return null;
}

@Override
public View getInfoContents(Marker marker) {
View v = layoutInflater.inflate(R.layout.tooltip_brewer, null);

TextView tvLat = (TextView) v.findViewById(R.id.tv_title);
TextView tvLng = (TextView) v.findViewById(R.id.tv_snippet);
Button button = (Button) v.findViewById(R.id.btn_button);
tvLat.setText("TestTooltip");
tvLng.setText("TestTooltip 1");
button.setOnClickListener(this);

return v;
}

@Override
public void onClick(View view) {
Log.d(Constants.TAG, "Test 01");
}
}

与标记的连接:

public void setInfoWindow(LayoutInflater inflater) {
this.layoutInflater = inflater;
map.setInfoWindowAdapter(new InfoHandler());
}

工具提示 XML:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_vertical">

<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="10dp"
android:orientation="vertical">

<TextView
android:id="@+id/tv_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Title"
android:textSize="18sp" />

<TextView
android:id="@+id/tv_snippet"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="snippet" />

</LinearLayout>

<Button
android:id="@+id/btn_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button" />

</LinearLayout>

现在一切正常接受我无法让点击事件在工具提示中的按钮上工作。有人对此有解决方案吗?

最佳答案

那是因为它不是实时 View ,所以你不能为所欲为。

Note: The info window that is drawn is not a live view. The view is rendered as an image (using View.draw(Canvas)) at the time it is returned. This means that any subsequent changes to the view will not be reflected by the info window on the map. To update the info window later (for example, after an image has loaded), call showInfoWindow(). Furthermore, the info window will not respect any of the interactivity typical for a normal view such as touch or gesture events. However you can listen to a generic click event on the whole info window as described in the section below.

查看文档

https://developers.google.com/maps/documentation/android/infowindows

关于Android:自定义工具提示 Google map 中的按钮单击事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23817168/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com