2017-02-24 9 views
0

こんにちは私は都市の関心のポイントを示すためにGoogleマップapiに基づいてマップとアンドロイドアプリを持っています。情報ウィンドウを追加する必要があります:マーカーをクリックするとウィンドウが開き、このウィンドウに画像と簡単な説明が表示されます。 私はいくつかのガイドを読んだが、私には役に立たなかった。おかげさまで インフォーワードウィンドウにテキストと画像を追加するにはどうすればよいですか?

答えて

0
/** 
    * Create a custom info window for Google maps to show the button. Ref: 
    * https://developers.google.com/maps/documentation/android-api/infowindows 
    */ 
    private class CustomInfoWindowAdapter implements InfoWindowAdapter { 

     private final View mCustomView; 

     CustomInfoWindowAdapter() { 
      mCustomView = getActivity() 
        .getLayoutInflater() 
        .inflate(R.layout.travel_tools_custom_map_info_window, null); 
     } 

     /** 
     * This method allow us to provide a view that will be used for the entire info window. 
     */ 
     @Override 
     public View getInfoWindow(Marker marker) { 
      //In this case we are inflating a custom view with all views already setup, so we don't 
      // need to do anything else. 
      return null; 
     } 

     /** 
     * This method allow us to just customize the contents of the window. 
     */ 
     @Override 
     public View getInfoContents(Marker marker) { 
      TextView tvTitle = ((TextView) mCustomView.findViewById(R.id.title)); 
      tvTitle.setText(marker.getTitle()); 

      return mCustomView; 
     } 
    } 

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:clipToPadding="false" 
    android:orientation="vertical"> 

    <TextView 
     android:id="@+id/title" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:textColor="?android:attr/textColorPrimary" 
     android:textStyle="bold"/> 

    <Button 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_marginBottom="8dp" 
     android:layout_marginEnd="8dp" 
     android:layout_marginStart="8dp" 
     android:layout_marginTop="8dp"/> 
</LinearLayout> 

@Override 
    public void onMapReady(GoogleMap googleMap) { 
     map.setInfoWindowAdapter(new CustomInfoWindowAdapter()); 
} 
関連する問題