如何在Google Map V2中的标记中偏移气球视图?

ben*_*eni 6 android android-maps-v2

单击标记时,会出现一个气球.但是在标记和气球之间有太大的空间,所以我怎么能减少这个距离?这就像使用中的setBalloonBottomOffset方法V1 Google Map.

custom balloon是这堂课:

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("");
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

我展示了一个标记

marker.showInfoWindow();
Run Code Online (Sandbox Code Playgroud)

我的气球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>
Run Code Online (Sandbox Code Playgroud)

Iva*_*sov 0

您是否尝试过在整个气球布局中使用负底部边距?就像这样:

\n\n
<RelativeLayout\n    android:layout_width="250dp"\n    android:layout_height="75dp"\n    android:background="@drawable/ballon"\n\n    android:layout_marginBottom="-8dp" >\n
Run Code Online (Sandbox Code Playgroud)\n\n

可能不起作用或导致内容在底部被切断,但作为最简单的方法仍然值得尝试。也许还有另一种方法可以欺骗GoogleMap类,但如果没有 API 的源代码,很难弄清楚。

\n\n

另一个提示:您可能不需要您的getInfoContents()方法 \xe2\x80\x93 只需返回null那里即可。null仅当您从getInfoWindow()参见此处)\xe2\x80\x93返回以将内容视图合并到默认信息窗口中时才会调用此方法,这显然不是您的目标,因为您想要移动气球。\n因此,您也可以扔掉mContents,它完全是多余的,只是占用内存来存储从未使用过的膨胀视图层次结构的另一个副本。

\n\n

告诉我保证金是否适合您。((View)mWindow.getParent())我们也可以尝试在显示项目时使用类似的东西,但这会比较棘手,所以我建议先尝试边距。

\n