在Google Maps Marker代码段中对齐文本

Mug*_*gen 3 android google-maps text-align line-breaks marker

我希望我的代码段中的字符串与中心对齐.

此外,片段中的断路器(\n)转换为空格,是否有插入断路器的方法?

我的相关代码:

GoogleMap map = ...
map.addMarker(new MarkerOptions().position(pos)
        .title("title")
        .snippet("body \n and mind");
Run Code Online (Sandbox Code Playgroud)

谢谢

Mug*_*gen 12

使用一些示例,以及来自以下内容的答案:自定义信息窗口适配器以及地图v2中的自定义数据,我遇到了以下解决方案:

marker.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:orientation="vertical" >

  <TextView
    android:id="@+id/info"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:gravity="center" />

 </RelativeLayout>
Run Code Online (Sandbox Code Playgroud)

Java的:

map.setInfoWindowAdapter(new InfoWindowAdapter() {

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

        @Override
        public View getInfoContents(Marker marker) {

            View v = getLayoutInflater().inflate(R.layout.marker, null);

            TextView info= (TextView) v.findViewById(R.id.info);

            info.setText(marker.getPosition().toString());

            return v;
        }
    });
Run Code Online (Sandbox Code Playgroud)