title: Using an xml Layout for a Google Map Marker for Android
body: <p>I want to use a layout and not a drawable for my <code>marker</code> I am using with Google Maps Api 2 for an Android app.  </p>
  
  <p>Like this:</p>
  
  <pre><code>  Marker m = googleMap
                          .addMarker(new MarkerOptions()
                                  .position(LOC)
                                  .snippet(user)
                                  .title(name)
                                  .icon(BitmapDescriptorFactory.fromResource(R.layout.map_marker)));
  </code></pre>
  
  <p>However, it seems this is only designed for use from <code>drawable</code> folder.</p>
  
  <p>I simply what an image with a background where I can change colors based on marker type.  This is the layout I want to use:</p>
  
  <pre><code>&lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:orientation="vertical"
      android:layout_width="50dp"
      android:layout_height="50dp"
      android:background="#222"
      android:id="@+id/llMarker"&gt;
  
      &lt;ImageView
          android:id="@+id/ivMarker"
          android:layout_marginTop="5dp"
          android:layout_width="40dp"
          android:layout_height="40dp" /&gt;
  
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>Pretty basic.  How can I use this as a marker? (or at least replicate the end result that I am going for?)</p>
  
  <p>The documents say you can use this:</p>
  
  <pre><code>fromResource (int resourceId)
  </code></pre>
  
  <p>So I assumed a layout might work.</p>
  
  <p><strong>UPDATE:</strong></p>
  
  <p>I have taken the concept from answer below and reworked some things; this still is not working; no errors.  Just will not show image.</p>
  
  <pre><code>        LayoutInflater inflater = (LayoutInflater) getActivity()
                  .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
          View v = inflater.inflate(R.layout.map_marker, null);
  
          m = googleMap
                  .addMarker(new MarkerOptions()
                          .position(LOC)
                          .snippet(user)
                          .title(name)
                          .icon(BitmapDescriptorFactory.fromBitmap(loadBitmapFromView(v))));
  </code></pre>
  
  <p>// method</p>
  
  <pre><code>  public static Bitmap loadBitmapFromView(View v) {
  
          if (v.getMeasuredHeight() &lt;= 0) {
              v.measure(WindowManager.LayoutParams.WRAP_CONTENT, WindowManager.LayoutParams.WRAP_CONTENT);
              Bitmap b = Bitmap.createBitmap(v.getMeasuredWidth(), v.getMeasuredHeight(), Bitmap.Config.ARGB_8888);
              Canvas c = new Canvas(b);
              v.layout(0, 0, v.getMeasuredWidth(), v.getMeasuredHeight());
              v.draw(c);
              return b;
          }
          return null;
      }
  </code></pre>