当前位置:  开发笔记 > 编程语言 > 正文

Google Map Fragment在NestedScrollView中滚动

如何解决《GoogleMapFragment在NestedScrollView中滚动》经验,为你挑选了1个好方法。



1> Ashish John..:

试试这个......使用带有可触摸包装的自定义地图片段.

MySupportMapFragment mSupportMapFragment;
mSupportMapFragment = (MySupportMapFragment) getChildFragmentManager().findFragmentById(R.id.googleMap);
if(mSupportMapFragment != null)
        mSupportMapFragment.setListener(new MySupportMapFragment.OnTouchListener() {
        @Override
        public void onTouch() {
            scrollView.requestDisallowInterceptTouchEvent(true);
        }
    });

MySupportMapFragment

public class MySupportMapFragment extends SupportMapFragment {

    private OnTouchListener mListener;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup parent, Bundle savedInstanceState) {

        View layout = super.onCreateView(inflater, parent, savedInstanceState);

        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);
        }
    }
}

推荐阅读
k78283381
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有