Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/195.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 如何在地图标记对象上使用ViewTreeObserver?_Android_Width_Android Viewtreeobserver - Fatal编程技术网

Android 如何在地图标记对象上使用ViewTreeObserver?

Android 如何在地图标记对象上使用ViewTreeObserver?,android,width,android-viewtreeobserver,Android,Width,Android Viewtreeobserver,我有一个自定义地图标记,我想根据标记的文本进行缩放。我要检索此标记的宽度。我面临的问题是,当应用程序首次启动时,宽度值为0。我来得太早了。但我无法让ViewTreeObserver实际工作。我做错了什么,有可能我没有引用正确的观点吗 // custom marker mCustomMarkerView = ((LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE)).inflate(R.l

我有一个自定义地图标记,我想根据标记的文本进行缩放。我要检索此标记的宽度。我面临的问题是,当应用程序首次启动时,宽度值为0。我来得太早了。但我无法让ViewTreeObserver实际工作。我做错了什么,有可能我没有引用正确的观点吗

        // 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
            }
        });
XML如下所示

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

    <RelativeLayout
        android:id="@+id/rl_custom_marker_wrapper"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content">

        <!-- custom marker image -->
        <ImageView
            android:id="@+id/iv_marker_bg"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/custom_marker"/>

        <!-- custom marker title -->
        <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"/>

    </RelativeLayout>

</FrameLayout>

提前谢谢你