android - 如何在 Google Map V2 中偏移标记中的气球 View ?

标签 android android-maps-v2

当我点击一个标记时,会出现一个气球。但是标记和气球之间的距离太大了,那么我该如何减少这个距离呢?。这就像在 V1 Google Map 中使用 setBalloonBottomOffset 方法。

我的自定义气球是这个类:

public class CustomInfoWindowAdapter implements InfoWindowAdapter {

    private final View mWindow;
    private final View mContents;

    public CustomInfoWindowAdapter(Activity activity) {
        LayoutInflater inflater = (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

        mWindow = inflater.inflate(R.layout.ballon, null);
        mContents = inflater.inflate(R.layout.ballon, null);
    }

    @Override
    public View getInfoWindow(Marker marker) {
        render(marker, mWindow);
        return mWindow;
    }

    @Override
    public View getInfoContents(Marker marker) {
        render(marker, mContents);
        return mContents;
    }

    private void render(Marker marker, View view) {
        String title = marker.getTitle();
        TextView titleUi = ((TextView) view.findViewById(R.id.txtTitle));
        if (title != null) {
            titleUi.setText(title);
        } else {
            titleUi.setText("");
        }

        String snippet = marker.getSnippet();
        TextView snippetUi = ((TextView) view.findViewById(R.id.txtPlace));
        if (snippet != null) {
            snippetUi.setText(snippet);
        } else {
            snippetUi.setText("");
        }
    }
}

我展示了一个像

这样的标记
marker.showInfoWindow();

我的气球 xml 是

<RelativeLayout
    android:layout_width="250dp"
    android:layout_height="75dp"
    android:background="@drawable/ballon" >

    <RelativeLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" >

        <LinearLayout
            android:id="@+id/linearLayout1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:orientation="vertical" >

            <TextView
                android:id="@+id/txtTitle"
                style="@style/Ballon_Title"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:ellipsize="end"
                android:paddingLeft="15dp"
                android:paddingRight="50dp"
                android:paddingTop="10dp"
                android:singleLine="true"
                android:text="Con mis amigos amigos" />

            <TextView
                android:id="@+id/txtPlace"
                style="@style/Ballon_Place"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:ellipsize="end"
                android:paddingBottom="20dp"
                android:paddingLeft="15dp"
                android:paddingRight="50dp"
                android:singleLine="true"
                android:text="Puerta del sol" />
        </LinearLayout>
    </RelativeLayout>

    <RelativeLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" >
    </RelativeLayout>

    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:paddingRight="12dp"
        android:paddingTop="18dp"
        android:src="@drawable/icon_arrow" />
</RelativeLayout>

最佳答案

默认情况下, map 标记“锚定”到布局底部的中间(即 anchor(0.5,1))。

您可以使用 MarkerOptions.anchor 更改 anchor 当您创建标记时。

关于android - 如何在 Google Map V2 中偏移标记中的气球 View ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14878607/

相关文章:

java - 安卓 cocos2d

java - 创建 map v2 扩展 fragment 时出错

android - 单击 InfoWindows 的突出显示时禁用?

android - 如何在我的 Android 设备上禁用已安装的 Google Play 服务版本?

Android计算多边形的面积

android - 使用 RecyclerView 时 notifydatasetchanged 是否调用 onCreateViewHolder

android - 安装错误 : INSTALL_FAILED_MISSING_SHARED_LIBRARY on Kindle fire

android - FirebaseRecyclerAdapter 数据库异常

Android 连接到远程 mysql 数据库 JDBC 与 JSON