我使用Google Maps Android API v2和Android一起显示当前位置与附近标记。使用Google Places API接收附近地点的位置和标题。问题在于,标题/摘要中的非英语名称以错误的方式显示,例如希伯来语名称。附上了屏幕截图。
由于阿拉伯语和希伯来语存在问题,而英语和俄语则没有问题,我猜测默认信息窗口实现可能存在与从右到左 (RTL) 语言相关的问题。特别是如果您在 Android 4.2 上运行测试,则可能是 Maps V2 的默认信息窗口内容错误地应用了各种 RTL 相关属性。
幸运的是,您可以提供自己的信息窗口内容,方法是实现 InfoWindowAdapter
并使 getInfoContents()
返回您想要在信息窗口中使用的 View
。
例如,这个示例项目(来自我的书的明天的更新)展示了如何使用此 InfoWindowAdapter
自定义信息窗口:
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);
}
}
如果您想要替换整个窗口,您需要让getInfoWindow()
返回一个View
。如果getInfoWindow()
返回null
,那么会使用getInfoContents()
来获取窗口内容。然后,您可以通过在GoogleMap
上调用setInfoWindowAdapter()
来附加一个InfoWindowAdapter
实例。
在您的情况下,您可以使用自己的布局来确保正确地实现RTL。这应该原则上可以解决此问题。可能 Maps V2 会做一些奇怪的事情,导致正常工作的RTL代码出现问题,这种情况下,您需要提交一个问题。
@Override
public View getInfoContents(Marker marker) {
TextView info = new TextView(ShareLocation.this);
info.setLayoutParams(new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT,
FrameLayout.LayoutParams.MATCH_PARENT));
info.setText(marker.getTitle() + "\n" + marker.getSnippet());
info.setTextColor(ShareLocation.this.getResources().getColor(R.color.black));return info;
}运行得很好。而主要的秘密是为什么谷歌错过了这种方式 :-) - Oleg KarakozTextView
支持阿拉伯语字符串。如果您遇到问题,请发布一个全新的 Stack Overflow 问题,展示您的代码以及可能出现的任何问题的截图。 - CommonsWarelayout_direction="LTR"
,这意味着您的标题不会在RTL桌面上翻转。解决方案很简单:”<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="48dp"
android:layoutDirection="locale"
>
....
</RelativeLayout>