How to use ViewTreeObserver on map marker object?
<p>I have a custom map marker that I would like to scale based on the text of the marker. I want to retrieve the width of this marker. The issue I am facing is that when the app is first launched, the width value is 0. I am getting the width too early. But I am unable to get ViewTreeObserver to actually work. What am I doing wrong, is it possible I am not referencing the correct view?</p>

<pre><code>        // custom marker
        mCustomMarkerView = ((LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE)).inflate(R.layout.custom_map_marker, null);
        tvCustomMarkerTitle = (FontedTextView) mCustomMarkerView.findViewById(R.id.tv_marker_title);
        ivCustomMarker = (ImageView) mCustomMarkerView.findViewById(R.id.iv_marker_bg);
        rlCustomMarkerWrapper = (RelativeLayout) mCustomMarkerView.findViewById(R.id.rl_custom_marker_wrapper);

        rlCustomMarkerWrapper.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
            @Override
            public void onGlobalLayout() {
                // do some work
            }
        });
</code></pre>

<p>The XML looks like the following</p>

<pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"&gt;

    &lt;RelativeLayout
        android:id="@+id/rl_custom_marker_wrapper"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"&gt;

        &lt;!-- custom marker image --&gt;
        &lt;ImageView
            android:id="@+id/iv_marker_bg"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/custom_marker"/&gt;

        &lt;!-- custom marker title --&gt;
        &lt;TextView
            android:id="@+id/tv_marker_title"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerInParent="true"
            android:textSize="@dimen/font_size_14"/&gt;

    &lt;/RelativeLayout&gt;

&lt;/FrameLayout&gt;
</code></pre>

<p>Thank you in advanced!</p>