2013-04-19 27 views
5

Chiều rộng tôi đặt trong bố cục InfoWindow tùy chỉnh của tôi dường như bị bỏ qua (nó luôn match_parent).Chiều rộng của bố cục InfoWindow tùy chỉnh của tôi bị bỏ qua trong Google Maps API Android v2

Tôi có thiếu gì đó không?

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

Rõ ràng đây chỉ là một vấn đề với RelativeLayouts. LinearLayouts hoạt động tốt. Vì vậy, tôi đã kết thúc bằng cách viết lại bố cục của mình thành LinearLayout. May mắn là nó khá đơn giản nên nó không phải là một vấn đề lớn. – Ridcully

Trả lời

0

Tôi cho rằng nó thực sự sẽ được wrap_content.

Cửa sổ thông tin cách hoạt động bằng cách vẽ Chế độ xem của bạn thành bitmap và không đặt nó vào bên trong bất kỳ Nhóm xem nào khác. layout_xxx được sử dụng bởi chế độ xem gốc.

Mã hóa các giá trị này trên một số hoặc tất cả trẻ em trong RelativeLayout của bạn có thể sẽ giải quyết được sự cố của bạn.

0

cố gắng sử dụng này trong getInfoWindow, getInfoContents trả về 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> 
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> 

Chỉ chnage các dp chiều rộng theo requiremnt bạn

Các vấn đề liên quan