How can I create a speech-bubble border for a Google Marker Custom Icon using Picasso?

前端 未结 3 548
后悔当初
后悔当初 2020-12-06 02:27

How can I use Picasso and Google Marker Custom Icon to achieve this feature?

I know how to use Picasso for the image, but I don\'t know how to add that \"ma

3条回答
  •  有刺的猬
    2020-12-06 03:04

    here marker view is your custom marker layout

        val view = LayoutInflater.from(context).inflate(R.layout.marker_view, 
        null,false)
    
        val bitmap = getBitmapFromView(view)
    
        // Uses a custom icon.
         mSydney = mMap.addMarker(MarkerOptions()
            .position(SYDNEY)
            .title("Sydney")
            .snippet("Population: 4,627,300")
            .icon(BitmapDescriptorFactory.fromResource(bitmap)))
    

    use this function to convert bitmap from view

    private fun getBitmapFromView(view: View): Bitmap {
            view.measure(MeasureSpec.UNSPECIFIED, MeasureSpec.UNSPECIFIED)
            val bitmap = Bitmap.createBitmap(view.measuredWidth, view.measuredHeight,
                    Bitmap.Config.ARGB_8888)
            val canvas = Canvas(bitmap)
            view.layout(0, 0, view.measuredWidth, view.measuredHeight)
            view.draw(canvas)
            return bitmap
        }
    

提交回复
热议问题