将片段添加到父滚动视图上的数组

Adding a fragment to an array on a parent scrollview

我需要将 MapView 添加到异常列表中,以便在用户触摸地图视图时滚动视图不会滚动。

<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">

    <org.xxx.ScrollViewWithMap
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:scrollbars="vertical"
        android:id="@+id/base_scrollview">

        <LinearLayout
            android:orientation="vertical"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content">

            <FrameLayout
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:id="@+id/content_fragment"
                android:layout_marginBottom="5dp" />

            <FrameLayout
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:id="@+id/map_fragment"
                android:layout_margin="10dp" />
        </LinearLayout>
    </org.xxx.ScrollViewWithMap>


</RelativeLayout>

在基本片段中,mapFragment 是通过以下方式添加的:

        LocationMapFragment locationMapFragment = new LocationMapFragment();
        locationMapFragment.setArguments(args);
        getChildFragmentManager().beginTransaction().add(R.id.map_fragment, locationMapFragment).commit();

现在我需要将此视图添加到 ScrollViewWithMap 中的数组中,但我该怎么做。在基本片段 'locationMapFragment' returns 中,getView() 为空,我不知道如何从片段中访问滚动视图。

[编辑:] 我确实尝试在 onAttach 上添加片段,但视图仍然是 'null':

@Override
public void onAttach(Activity activity) {
    super.onAttach(activity);
    try {
        mListener = (OnFragmentInteractionListener) activity;
    } catch (ClassCastException e) {
        throw new ClassCastException(activity.toString()
                + " must implement OnFragmentInteractionListener");
    }

    ScrollViewWithMap scrollview = (ScrollViewWithMap) activity.findViewById(R.id.base_scrollview);
    scrollview.addInterceptScrollView(this.getView());
}

尝试使用 ViewTreeObserver:

ViewTreeObserver observer = yourView.getViewTreeObserver();
        observer.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
            @Override
            public void onGlobalLayout() {
                //add in list here

            }
        });