2013-04-19 5 views
5

Die Breite, die ich in meinem benutzerdefinierten InfoWindow-Layout festgelegt habe, scheint ignoriert zu werden (es ist immer match_parent).Breite meines benutzerdefinierten InfoWindow-Layouts wird in Google Maps Android API v2 ignoriert

Fehle ich etwas?

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

<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> 
+0

Offensichtlich ist dies nur ein Problem mit RelativeLayouts ist. LinearLayouts funktionieren gut. Also habe ich mein Layout in ein LinearLayout umgeschrieben. Glücklicherweise war es ziemlich einfach und so war es kein großes Problem. – Ridcully

Antwort

0

Ich nehme an, es tatsächlich wrap_content würde.

Das Weg-Info-Fenster funktioniert, indem Sie Ihre Ansicht auf eine Bitmap zeichnen und sie nicht in eine andere ViewGroup einfügen. layout_xxx wird von der übergeordneten Ansicht verwendet.

Das Codieren dieser Werte auf einigen oder allen untergeordneten Elementen Ihres RelativeLayout löst wahrscheinlich Ihr Problem.

0

versuchen, dies in getInfoWindow zu verwenden, getInfoContents null zurück:

<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> 
0
<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> 

einfach die Breite dp chnage nach Ihrem requiremnt