我想在单击标记时显示一个自定义信息窗口.
我希望它是这样的:
ImageVIEwTextVIEwTextVIEwTextVIEwbutton button
我看到了其他人对此的提问,但是仍然令人困惑.
解决方法:
关于ImageVIEw和TextVIEw,请尝试以下 *** 作:
设置信息窗口布局:infowindowlayout.xml
<?xml version="1.0" enCoding="utf-8"?><linearLayout xmlns:androID="http://schemas.androID.com/apk/res/androID"androID:layout_wIDth="wrap_content"androID:layout_height="wrap_content"androID:orIEntation="vertical"androID:background="#FFFFFF" ><ImageVIEw androID:ID="@+ID/imageVIEw1" androID:layout_wIDth="wrap_content" androID:layout_height="wrap_content" /><TextVIEw androID:ID="@+ID/textVIEw1" androID:layout_wIDth="wrap_content" androID:layout_height="wrap_content" androID:text="TextVIEw" /><TextVIEw androID:ID="@+ID/textVIEw2" androID:layout_wIDth="wrap_content" androID:layout_height="wrap_content" androID:text="TextVIEw" /></linearLayout>
在您的MapActivity中(这是一个标记的示例,但是您也可以将其用于其他标记):
public class MapActivity extends Activity {private GoogleMap mMap;private Marker Somewhere;private int markerclicked;@OverrIDeprotected voID onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentVIEw(R.layout.activity_map);......final LatLng somewhere = new LatLng(..., ...);Somewhere=mMap.addMarker(new MarkerOptions().position(somewhere).Title("YOUR Title").snippet("INFO").icon(BitmapDescriptorFactory.fromresource(R.drawable.pin)));.........mMap.setInfoWindowAdapter(new InfoWindowAdapter() { // Use default InfoWindow frame @OverrIDe public VIEw getInfoWindow(Marker arg0) { return null; } // defines the contents of the InfoWindow @OverrIDe public VIEw getInfoContents(Marker arg0) { // Getting vIEw from the layout file infowindowlayout.xml VIEw v = getLayoutInflater().inflate(R.layout.infowindowlayout, null); LatLng latLng = arg0.getposition(); ImageVIEw im = (ImageVIEw) v.findVIEwByID(R.ID.imageVIEw1); TextVIEw tv1 = (TextVIEw) v.findVIEwByID(R.ID.textVIEw1); TextVIEw tv2 = (TextVIEw) v.findVIEwByID(R.ID.textVIEw2); String Title=arg0.getTitle(); String informations=arg0.getSnippet(); tv1.setText(Title); tv2.setText(informations); if(onMarkerClick(arg0)==true && markerclicked==1){ im.setimageResource(R.drawable.yourdrawable); } return v; } });}public boolean onMarkerClick(final Marker marker) {if (marker.equals(Somewhere)) { markerclicked=1; return true; }return false; }
关于按钮,图像按钮等,是没有办法的. documentation说:
As mentioned in the prevIoUs section on info windows, an info window is not a live VIEw, rather the vIEw is rendered as an image onto the map. As a result, any Listeners you set on the vIEw are disregarded and you cannot distinguish between click events on varIoUs parts of the vIEw. You are advised not to place interactive components — such as buttons, checkBoxes, or text inputs — within your custom info window.
无论如何,似乎有解决方案,请参见this answer here.我不知道它是否适用于我的代码,但似乎可以使用按钮和图像按钮.
总结以上是内存溢出为你收集整理的Google Maps Android的自定义信息窗口全部内容,希望文章能够帮你解决Google Maps Android的自定义信息窗口所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)