需要 android.gms.maps.GoogleMap 找到 com.examle.myprojec.WorkAroundFragment

Required android.gms.maps.GoogleMap found com.examle.myprojec.WorkAroundFragment

首先我知道 getMap() 方法已被弃用,但为了避免 scrollview inside map 我使用了这个方法:

http://www.londatiga.net/it/programming/android/how-to-make-android-map-scrollable-inside-a-scrollview-layout/

正在创建自定义片段。但是,在那个 getMap() 点上,我不知道该怎么做。

这是我的自定义片段:

public class WorkaroundMapFragment extends SupportMapFragment {
    private OnTouchListener mListener;
    @Override
    public View onCreateView(LayoutInflater layoutInflater, ViewGroup viewGroup, Bundle savedInstance) {
        View layout = super.onCreateView(layoutInflater, viewGroup, savedInstance);
        TouchableWrapper frameLayout = new TouchableWrapper(getActivity());
        frameLayout.setBackgroundColor(getResources().getColor(android.R.color.transparent));
        ((ViewGroup) layout).addView(frameLayout,
                new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
        return layout;
    }
    public void setListener(OnTouchListener listener) {
        mListener = listener;}
    public interface OnTouchListener {
        public abstract void onTouch();
    }
    public class TouchableWrapper extends FrameLayout {
        public TouchableWrapper(Context context) {
            super(context);
        }
        @Override
        public boolean dispatchTouchEvent(MotionEvent event) {
            switch (event.getAction()) {
                case MotionEvent.ACTION_DOWN:
                    mListener.onTouch();
                    break;
                case MotionEvent.ACTION_UP:
                    mListener.onTouch();
                    break;
            }
            return super.dispatchTouchEvent(event);
        }
    }
}

这是我的 xml mapfragment 代码:

<fragment xmlns:tools="http://schemas.android.com/tools"
            android:id="@+id/map"
            android:name="com.google.android.gms.maps.SupportMapFragment"
            android:layout_width="0dp"
            android:layout_height="0dp"
            android:layout_marginEnd="8dp"
            android:layout_marginStart="8dp"
            android:layout_marginTop="8dp"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/guideline3"
            tools:context="com.example.mapwithmarker.MapsMarkerActivity"
        class="com.example.jonida.restsapp.customFragment.WorkaroundMapFragment"/>

这是我在 onViewCreated 中的代码,(我没有在这个项目的活动中做任何事情。)

public class OrderDetailsActivityFragment extends Fragment implements OnMapReadyCallback {
    @BindView(R.id.scrollView_order_details)
    ScrollView mScrollView;

    private GoogleMap googleMap;
 @Override
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);

        googleMap=((WorkaroundMapFragment)getChildFragmentManager().findFragmentById(R.id.map)).getMap //Here is my problem :/ ;
        ((WorkaroundMapFragment) getChildFragmentManager().findFragmentById(R.id.map)).setListener(new WorkaroundMapFragment.OnTouchListener() {
            @Override
            public void onTouch() {
   mScrollView.requestDisallowInterceptTouchEvent(true);}});
}

如有任何建议,我将不胜感激,谢谢。

Required android.gms.maps.GoogleMap found com.examle.myprojec.WorkAroundFragment

根据您的错误,您需要将 googleMap 声明为 WorkaroundMapFragment 而不是 GoogleMap

使用这个

 private WorkaroundMapFragment  googleMap = (WorkaroundMapFragment) getChildFragmentManager()
                    .findFragmentById(R.id.map);
            googleMap.getMapAsync(this);


            ((WorkaroundMapFragment) getChildFragmentManager().findFragmentById(R.id.flysl_map))
                    .setListener(new WorkaroundMapFragment.OnTouchListener() {
                        @Override
                        public void onTouch() {
                            mScrollView.requestDisallowInterceptTouchEvent(true);
                        }
                    });

而不是这个

googleMap=((WorkaroundMapFragment)getChildFragmentManager().findFragmentById(R.id.map)).getMap //Here is my problem :/ ;
        ((WorkaroundMapFragment) getChildFragmentManager().findFragmentById(R.id.map)).setListener(new WorkaroundMapFragment.OnTouchListener() {
            @Override
            public void onTouch() {
   mScrollView.requestDisallowInterceptTouchEvent(true);}});

编辑

<fragment xmlns:tools="http://schemas.android.com/tools"
            android:id="@+id/map"
            android:layout_width="0dp"
            android:layout_height="0dp"
            android:layout_marginEnd="8dp"
            android:layout_marginStart="8dp"
            android:layout_marginTop="8dp"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/guideline3"
            tools:context="com.example.mapwithmarker.MapsMarkerActivity"
            class="com.example.jonida.restsapp.customFragment.WorkaroundMapFragment"/>