title: Android display drawable on the map
body: <p>I am trying to display custom drawable on the map view but I can observe very strange behavior, the drawable draws multiple times and the worst thing it displays one time incorrectly. Also this drawable displays perfect with ImageView, but not as MapView overlay...</p>
  
  <p><img src="https://i.stack.imgur.com/5ME10.png" alt="enter image description here"></p>
  
  <p>Here is my custom drawable:</p>
  
  <pre><code>public class CustomDrawable extends Drawable {
      private Bitmap mBitmap;
      private int mWidth;
      private int mHeight;
      private int mDrawLeft;
      private int mDrawTop;
      private int mColor;
  
      public ChatIconDrawable(Resources res, int color) {
          this.mColor = color;
          this.mBitmap = BitmapFactory.decodeResource(res, R.drawable.chat_icon);
          this.mWidth = mBitmap.getWidth();
          this.mHeight = mBitmap.getHeight();
          setBounds(-mWidth, -mHeight, 0, 0);
      }
  
      @Override
      public void draw(Canvas canvas) {
          ShapeDrawable shapeDrawable = new ShapeDrawable(new OvalShape());
          shapeDrawable.getPaint().setColor(mColor);
          shapeDrawable.setBounds(2 - mWidth, 3 - mHeight, mWidth - 2 - mWidth, mHeight - mHeight / 4 - mHeight);
          shapeDrawable.draw(canvas);
          canvas.drawBitmap(mBitmap, mDrawLeft, mDrawTop, null);
      }
  
      @Override
      public int getOpacity() {
          return PixelFormat.OPAQUE;
      }
  
      @Override
      public void setBounds(int left, int top, int right, int bottom) {
          mDrawLeft = left + (right - left - mWidth) / 2;
          mDrawTop = top + (bottom - top - mHeight) / 2;
      }
  
      @Override
      public void setBounds(Rect bounds) {
          super.setBounds(bounds);
      }
  
      @Override
      public void setAlpha(int alpha) {
  //      throw new UnsupportedOperationException(
  //              "Not supported with this drawable");
      }
  
      @Override
      public void setColorFilter(ColorFilter cf) {
  //      throw new UnsupportedOperationException("Not supported with this drawable");
      }
  
      @Override
      public void setDither(boolean dither) {
  //      throw new UnsupportedOperationException("Not supported with this drawable");
      }
  
      @Override
      public void setFilterBitmap(boolean filter) {
  //      throw new UnsupportedOperationException("Not supported with this drawable");
      }
  
      @Override
      public int getIntrinsicWidth() {
          return mWidth;
      }
  
      @Override
      public int getIntrinsicHeight() {
          return mHeight;
      }
  
      @Override
      public int getMinimumWidth() {
          return mWidth;
      }
  
      @Override
      public int getMinimumHeight() {
          return mHeight;
      }
  }
  </code></pre>
  
  <p>Basically custom drawable draws the background with some color (it may vary) and then draws on top static bitmap to produce right figure.</p>
  
  <p>To draw this on the map I use ItemizedOverlay.</p>
  
  <p>As you can see the problem in that this drawable draws multiple times and with different placement... please advice because it is not clear for me whats wrong. Thank you.</p>