Rotating drawable via XML not working with marker on GoogleMap V2

我怕爱的太早我们不能终老 提交于 2019-12-06 07:10:09

You cannot use non-PNG resources as a Marker's icon.

You can however load such Drawable into memory, draw it into a Bitmap using Canvas and send that Bitmap to MarkerOptions.icon using BitmapDescriptorFactory.fromBitmap(...).

Ok the problem seems to me like that (as I thought):

You're having a problem in .icon(BitmapDescriptorFactory.fromResource(R.drawable.myxmldrawable), because R.drawable only pertains to the files inside the drawable folders.

To get the resource use this:

getResources().getIdentifier(myxmldrawable,"drawable", getPackageName()) The myxmldrawable used above is assigned variable for the XML icon attribute Use this to get the icon dynamically:

.icon(BitmapDescriptorFactory .fromResource(getResources().getIdentifier(icon,"drawable", getPackageName()))

That should do it for ya.

Cheers :)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!