简体   繁体   English

Google Maps Android API v2中会忽略我的自定义InfoWindow布局的宽度

[英]Width of my custom InfoWindow layout is ignored in Google Maps Android API v2

The width I set in my custom InfoWindow layout seems to be ignored (it always match_parent). 我在自定义InfoWindow布局中设置的宽度似乎被忽略(它总是match_parent)。

Am I missing something? 我错过了什么吗?

mMap.setInfoWindowAdapter(new InfoWindowAdapter() {

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

    @Override
    public View getInfoContents(Marker arg0) {

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

        // set my custom data

        return v;

    }
});

info_window_layout.xml info_window_layout.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="100dp"
    android:layout_height="50dp"
    android:padding="5dp" >

    <!-- some custom stuff -->

</RelativeLayout>

I suppose it would actually be wrap_content. 我想它实际上是wrap_content。

The way info window works is by drawing your View to a bitmap and not putting it inside any other ViewGroup. 信息窗口的工作方式是将View绘制到位图,而不是将其放在任何其他ViewGroup中。 layout_xxx are used by parent View. layout_xxx由父View使用。

Hardcoding these values on some or all children of your RelativeLayout will probably solve your problem. 在RelativeLayout的部分或全部子项上对这些值进行硬编码可能会解决您的问题。

try to use this in getInfoWindow, getInfoContents return null: 尝试在getInfoWindow中使用它,getInfoContents返回null:

<LinearLayout
            xmlns:android="http://schemas.android.com/apk/res/android"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical"
            android:background="@drawable/transparent">

        <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:gravity="center_horizontal"
                android:orientation="vertical">

            <!-- some custom stuff -->

        </LinearLayout>
    </LinearLayout>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:background="#8BC34A"
android:orientation="vertical"
android:paddingBottom="@dimen/small_padding"
android:paddingLeft="@dimen/very_samll_padding"
android:paddingRight="@dimen/very_samll_padding"
android:paddingTop="@dimen/small_padding">


<LinearLayout
    android:layout_width="320dp"
    android:layout_height="wrap_content"
    android:orientation="vertical">

    <TextView
        android:id="@+id/tv_address"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textColor="@color/white" />

    <LinearLayout
        android:id="@+id/ll_latlong"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/tv_address"
        android:layout_marginTop="@dimen/very_samll_padding"
        android:orientation="horizontal">

        <TextView
            android:id="@+id/tv_lat"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center_vertical"
            android:textColor="@color/white" />

        <View
            android:layout_width="1dp"
            android:layout_height="12dp"
            android:layout_gravity="center_vertical"
            android:layout_marginLeft="@dimen/small_padding"
            android:layout_marginRight="@dimen/small_padding"
            android:background="@color/white" />

        <TextView
            android:id="@+id/tv_long"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center_vertical"
            android:textColor="@color/white" />

    </LinearLayout>
</LinearLayout>

Just chnage the width dp according to your requiremnt 只需根据您的要求选择宽度dp即可

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM