title: Popup or layout over marker Android
body: <p>I want to put a custom layout over a marker. So far I got this:</p>
  
  <p>default_marker_info_window.xml</p>
  
  <pre><code>&lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:orientation="vertical"&gt;
  
      &lt;ViewFlipper
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:id="@+id/markerInfoContainer"
          android:background="@android:color/holo_red_dark"
          android:maxWidth="250dp"&gt;
      &lt;/ViewFlipper&gt;    
  
      &lt;ImageView
          android:layout_width="20dp"
          android:layout_height="15dp"
          android:background="@drawable/ic_down_arrow"
          android:layout_gravity="center|top"/&gt;
  
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>default_marker_info_layout.xml</p>
  
  <pre><code>&lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:orientation="vertical" android:layout_width="match_parent"
      android:layout_height="match_parent"&gt;
  
      &lt;LinearLayout
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:orientation="vertical"&gt;
  
          &lt;TextView
              android:id="@+id/tvTitulo"
              android:layout_width="match_parent"
              android:layout_height="wrap_content"
              android:textStyle="bold"
              android:gravity="center"/&gt;
  
          &lt;TextView
              android:id="@+id/tvCuerpo"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"/&gt;
  
          &lt;Button
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:text="press me 1"
              android:id="@+id/button"/&gt;
  
          &lt;Button
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:text="press me 2"
              android:id="@+id/button2"/&gt;
  
      &lt;/LinearLayout&gt;
  
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>MapActivity.java</p>
  
  <pre><code>public class MapActivity extends Activity implements GoogleMap.OnMapLongClickListener{
  
      protected GoogleMap mMap;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          ...
          setUpMapIfNeeded();
          mMap.setOnMarkerClickListener(new GoogleMap.OnMarkerClickListener() {
              @Override
              public boolean onMarkerClick(Marker marker) {
  
                  View mainView = getLayoutInflater().inflate(R.layout.default_marker_info_window, null);
                  ViewFlipper markerInfoContainer = (ViewFlipper)mainView.findViewById(R.id.markerInfoContainer);
                  View viewContainer = getLayoutInflater().inflate(R.layout.default_marker_info_layout, null);
                  TextView tvTitulo = (TextView) viewContainer.findViewById(R.id.tvTitulo);
                  TextView tvCuerpo = (TextView) viewContainer.findViewById(R.id.tvCuerpo);
                  tvTitulo.setText(marker.getTitle());
                  tvCuerpo.setVisibility(View.GONE);
  
                  markerInfoContainer.addView(viewContainer);
  
                  PopupWindow popupWindow = new PopupWindow(mainView, ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
                  popupWindow.showAtLocation(findViewById(R.id.map), Gravity.CENTER_HORIZONTAL, 0, 0); //map is the fragment on the activity layout where I put the map   
  
                  return true;
              }
          });
          ...
      }
  ...
  }
  </code></pre>
  
  <p>But I have a couple of problems.</p>
  
  <p>Problem 1: the popup shows over (3D) the marker (hidding it). I want to position it above it (2D), like this:</p>
  
  <p><a href="https://i.stack.imgur.com/HU8If.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/HU8If.png" alt="Position of popup I want"></a></p>
  
  <p>May be by help of <code>x</code> and <code>y</code> position of the marker and using them on <code>popupWindow.showAtLocation</code>. But if you have other solutions, I will listen to them.</p>
  
  <p>Problem 2: When I slide over the map, the layout keep on center of the screen, but I want to keep it over the marker.</p>
  
  <p><a href="https://i.stack.imgur.com/D8uQ5.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/D8uQ5.png" alt="Problem while sliding on map"></a></p>
  
  <p>Note: I can't use <code>mMap.setInfoWindowAdapter</code> because I will lose the button's click listeners.</p>