iTu*_*rki 9 android google-maps-markers google-maps-android-api-2
这是我向我的GoogleMap添加新标记的代码:
MarkerOptions m = new MarkerOptions();
m.title(title);
m.snippet(snippet);
m.position(location);
mMap.addMarker(m);
mMap.setOnInfoWindowClickListener(new OnInfoWindowClickListener() {
@Override
public void onInfoWindowClick(Marker marker) {
Toast.makeText(DemoActivity.this, "WindowClicked: "+ marker.getTitle() + ":" + marker.getSnippet(),
Toast.LENGTH_SHORT).show();
}
});
Run Code Online (Sandbox Code Playgroud)
现在,当我title和我snippet的英语时,这很好用.在infoWindow和Toast按预期工作.
但是,在我的情况下,title并且snippet是阿拉伯语,Toast工作正常,但InfoWindow显示空窗口.
在我看来,这似乎是一个与阿拉伯语有关的错误.有办法解决它吗?
@jimmithy的回答解决了我的问题.
这仅仅是一个三步实现从它这个项目:
第1步:创建infoWindow的布局.这是popup.xml代码:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageView
android:id="@+id/icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:padding="2dip"
android:src="@drawable/ic_launcher"
android:contentDescription="@string/icon"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="25sp"
android:textStyle="bold"/>
<TextView
android:id="@+id/snippet"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="15sp"/>
</LinearLayout>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
第2步:创建InfoWindowAdapter的实现.这是PopupAdapter课程:
class PopupAdapter implements InfoWindowAdapter {
LayoutInflater inflater=null;
PopupAdapter(LayoutInflater inflater) {
this.inflater=inflater;
}
@Override
public View getInfoWindow(Marker marker) {
return(null);
}
@Override
public View getInfoContents(Marker marker) {
View popup=inflater.inflate(R.layout.popup, null);
TextView tv=(TextView)popup.findViewById(R.id.title);
tv.setText(marker.getTitle());
tv=(TextView)popup.findViewById(R.id.snippet);
tv.setText(marker.getSnippet());
return(popup);
}
}
Run Code Online (Sandbox Code Playgroud)
第3步:在您的活动中,将您的适配器设置为GoogleMap:
mMap.setInfoWindowAdapter(new PopupAdapter(getLayoutInflater()));
Run Code Online (Sandbox Code Playgroud)
你就定了!
解决这个问题的方法是显示自定义信息窗口.您可以通过创建InfoWindowAdapter并使用GoogleMap.setInfoWindowAdapter()进行设置来完成此操作.
要替换默认信息窗口,请使用自定义呈现覆盖getInfoWindow(Marker),并为getInfoContents(Marker)返回null.要仅替换默认信息窗口框架(标注气泡)中的信息窗口内容,请在getInfoWindow(标记)中返回null并改为覆盖getInfoContents(标记).
更多信息:https://developers.google.com/maps/documentation/android/marker#info_windows
| 归档时间: |
|
| 查看次数: |
2386 次 |
| 最近记录: |