Aligning the text in Google Maps Marker snippet

我们两清 提交于 2019-12-21 20:19:32

问题


I want the string in my snippet to be aligned to the center.

Also, line breakers (\n) in the snippet are converted to spaces, is there a way to insert line breakers?

My relevant code:

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

Thanks


回答1:


Using some examples, as well as answers from: custom info window adapter with custom data in map v2, I've come across the following solution:

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>

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;
        }
    });


来源:https://stackoverflow.com/questions/15783227/aligning-the-text-in-google-maps-marker-snippet

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!