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

后端 未结 7 740
忘了有多久
忘了有多久 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 10:02

    The easiest way is to wrap the map fragment inside a FrameLayout along with an ImageView. The Imageview would display a rounded rectangle on top of the map fragment. In its simplest form you will see the map fragment inside the rounded rectangle with its corners sticking out of the rounded rectangle because the map view itself is not rounded. To overcome this visual oddity simply apply a layout_margin value on map fragment. The value should be equal to the rectangle's border width.

       
    
        
    
        
    
    
    

    The rectangle drawable is defined as an xml shape as below

    
    
    
        
    
        
    
    
    

    Notice the stroke width of the rectangle is 3dp that is exactly the same value we applied to the layout_margin property of the map fragment. The result is a nicely round cornered map fragment as shown in the screenshot below

提交回复
热议问题