Is there a way to implement rounded corners to a Mapfragment?

后端 未结 7 742
忘了有多久
忘了有多久 2020-11-30 09:10

I want to give the map a nice looking rounded corners as the two boxes below it have. I can\'t do it with the map fragment it self because there is not a background property

7条回答
  •  盖世英雄少女心
    2020-11-30 09:54

    For other people looking into this, I just tackled this using GoogleMap.snapshot and manipulating the bitmap result with this stack over flow answer: How to make an ImageView with rounded corners?

    Mind you this is only valid if you are going to have a static map that is not going to be interacted with.

    Make sure you take the snap shot after the map is loaded.

    I updated the image view helper code to draw with path to support rounding only some corners. ie. If you want to round only 2 of the corners.

    You just need the path round rect function that takes a float[]

    I show a progress bar until I get a callback from GoogleMap loaded listener than I take the snapshot.

    If you take your snapshot too early you will get can't create bitmap with 0 width and height error.

    Hope this helps someone looking for rounded corners or other weird shape in static map snapshot.

提交回复
热议问题