0

I have a bitmap thumbnail for a map and I want to add the a map marker in the center but am struggling to do so. I was able to overlay the two bitmaps but the the one in front is significantly smaller and not centered. Is there a way to center the bitmap and scale it up? This is what it looks like:

enter image description here

I looked at this Android: How to overlay-a-bitmap/draw-over a bitmap? and it helped but the map marker is very small and off centered. Thanks

  • why don't you user FrameLayout, let the layout have two child (ImageView) let the first child draw bitmap, set the layout gravity for second child as center, and set it to draw your overlay icon, it will reap exactly what you want. – Techfist Jul 18 '17 at 05:31
  • @T I have other types of attachments like pictures and such so I wouldn't want a pin in all of them. Also, I edited the question description given that I made some progress on adding the two bitmaps. I apologize for the change –  Jul 18 '17 at 05:44
  • cant see you attached image, try attaching it again. – Techfist Jul 18 '17 at 05:59
  • I removed and added the image again –  Jul 18 '17 at 06:08
  • so you need overlays at specific points over a map? if this is what you want then start Exploring MapView it let you add pins at specific geo points. – Techfist Jul 18 '17 at 06:58

2 Answers2

1

Update:

I ended up solving it this way. I'll leave my solution for anyone who needs it in the future. Here it goes:

    public static Bitmap overlay(Bitmap bmp1, Bitmap bmp2) {
    Bitmap resizedBitmap = Bitmap.createScaledBitmap(bmp2, 500, 500, false);
    Bitmap bitmapWithOverlay = Bitmap.createBitmap(bmp1.getWidth(), bmp1.getHeight(), bmp1.getConfig());
    Canvas canvas = new Canvas(bitmapWithOverlay);

    canvas.drawBitmap(bmp1, new Matrix(), null);
    canvas.drawBitmap(resizedBitmap, ((bmp1.getWidth()/2)-250), ((bmp1.getHeight()/2)-450), null);

    return bitmapWithOverlay;
}

and here is the process of getting the bitmap from a drawable

        Bitmap icon = BitmapFactory.decodeResource(getActivity().getBaseContext().getResources(),
            R.drawable.your_icon);
0

You can put both in the same FrameLayout. FrameLayout is build to only have one child, if you put more childs into it they will overlap. Ty this.

And also putting more childs into FrameLayout isn't bad practice.

user221256
  • 415
  • 5
  • 14