I'm trying to add custom view to google map Marker:
- I inflate a layout. <- this is the problem
- Then transform it to Bitmap.
- Generate Marker.
So I have layout home_marker_container.xml
:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="@dimen/home_map_marker_size"
android:layout_height="@dimen/home_map_marker_size"
android:background="@color/black"
android:id="@+id/frame">
<TextView
android:layout_width="12dp"
android:layout_height="12dp"
android:text="5"
android:textSize="10dp"
android:background="@color/white"
android:layout_centerInParent="true"
android:gravity="center" />
</RelativeLayout>
and I inflate it with
ViewGroup home_marker_container = (ViewGroup) layoutInflater.inflate(R.layout.home_marker_container, null, false);
Then transform View to Bitmap:
So I add it to marker with Google Maps Android API Utility Library via IconGenerator which basically transforms View to Bitmap:
iconGenerator.setContentView(home_marker_container);
iconGenerator.setContentPadding(horizontal_padding, vertical_padding, horizontal_padding, vertical_padding);
Bitmap iconBitmap = iconGenerator.makeIcon();
And after that I realized that inflating does not work as I expected because I give null
to ViewGroup root
parameter in inflate(int resource, ViewGroup root, boolean attachToRoot)
and thus
android:layout_width="@dimen/home_map_marker_size"
android:layout_height="@dimen/home_map_marker_size"
is not taken from xml. Why and how to fix it?