【问题标题】:Aligning the text in Google Maps Marker snippet对齐谷歌地图标记片段中的文本
【发布时间】:2023-03-20 23:07:02
【问题描述】:

我希望我的 sn-p 中的字符串与中心对齐。

另外,sn-p中的换行符(\n)被转换为空格,有没有办法插入换行符?

我的相关代码:

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

谢谢

【问题讨论】:

  • 您可以定义自己的InfoWindowAdapter。查看Google Maps Demo,您可以在其中找到 MarkerDemoActivity.java,他们在其中创建 CustomInfoWindowAdapter 并为其分配自定义 .xml 文件。

标签: android google-maps line-breaks marker text-align


【解决方案1】:

使用一些示例以及来自custom info window adapter with custom data in map 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>

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-08-19
    • 1970-01-01
    • 1970-01-01
    • 2016-04-30
    • 1970-01-01
    • 2023-03-19
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多