zoukankan      html  css  js  c++  java
  • 解决ScrollView嵌套百度地图滑动冲突

    一、问题描述

    scrollview中嵌套百度地图时会出现滑动冲突,地图无法滑动的情况。

    二、期望结果

    焦点在地图上时,只有地图移动,焦点在地图外部时,可以滑动scrollview。

    三、解决方法

    自定义包裹地图的容器

    package com.aldx.kangdasupervisor.view;
    
    import android.content.Context;
    import android.util.AttributeSet;
    import android.view.MotionEvent;
    import android.widget.LinearLayout;
    
    /**
     * author: chenzheng
     * created on: 2019/7/9 11:20
     * description:
     */
    public class BaiduMapContainer extends LinearLayout {
        private MyScrollview scrollView;
        public BaiduMapContainer(Context context) {
            super(context);
        }
        public BaiduMapContainer(Context context, AttributeSet attrs) {
            super(context, attrs);
        }
        public void setScrollView(MyScrollview scrollView) {
            this.scrollView = scrollView;
        }
        @Override
        public boolean onInterceptTouchEvent(MotionEvent ev) {
            if (ev.getAction() == MotionEvent.ACTION_UP) {
                scrollView.requestDisallowInterceptTouchEvent(false);
            } else {
                scrollView.requestDisallowInterceptTouchEvent(true);
            }
            return false;
        }
        @Override
        public boolean onTouchEvent(MotionEvent event) {
            return true;
        }
    }

    自定义scrollview

    package com.aldx.kangdasupervisor.view;
    
    import android.content.Context;
    import android.util.AttributeSet;
    import android.view.MotionEvent;
    import android.view.ViewConfiguration;
    import android.widget.ScrollView;
    
    /**
     * author: chenzheng
     * created on: 2017/7/5 8:46
     * description:
     */
    
    public class MyScrollview extends ScrollView {
        private int downX;
        private int downY;
        private int mTouchSlop;
    
        public MyScrollview(Context context) {
            super(context);
            mTouchSlop = ViewConfiguration.get(context).getScaledTouchSlop();
        }
    
        public MyScrollview(Context context, AttributeSet attrs) {
            super(context, attrs);
            mTouchSlop = ViewConfiguration.get(context).getScaledTouchSlop();
        }
    
        public MyScrollview(Context context, AttributeSet attrs, int defStyleAttr) {
            super(context, attrs, defStyleAttr);
            mTouchSlop = ViewConfiguration.get(context).getScaledTouchSlop();
        }
    
        @Override
        public boolean onInterceptTouchEvent(MotionEvent e) {
            int action = e.getAction();
            switch (action) {
                case MotionEvent.ACTION_DOWN:
                    downX = (int) e.getRawX();
                    downY = (int) e.getRawY();
                    break;
                case MotionEvent.ACTION_MOVE:
                    int moveY = (int) e.getRawY();
                    if (Math.abs(moveY - downY) > mTouchSlop) {
                        return true;
                    }
            }
            return super.onInterceptTouchEvent(e);
        }
    }

    绑定scrollview与MapView

    bannerContainer.setScrollView(myScrollview);

    布局

    <com.aldx.kangdasupervisor.view.BaiduMapContainer
                    android:id="@+id/bannerContainer"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content">
    
                    <com.baidu.mapapi.map.TextureMapView
                        android:id="@+id/bmapView"
                        android:layout_width="match_parent"
                        android:layout_height="200dp"
                        android:clickable="true" />
    
                </com.aldx.kangdasupervisor.view.BaiduMapContainer>
  • 相关阅读:
    Adobe Photoshop CS6+blend4 获取png图片data数据
    Git使用教程
    wpf-Datagrid每行combobox设置不同值
    wpf-阿里巴巴图库获取path data数据
    wpf-效果
    wpf-datagrid/listbox隔行换色
    wpf-DataGrid分页
    【学习笔记】委托、匿名方法、Lambda表达式和事件
    【学习笔记】泛型
    【学习笔记】VS常用快捷键
  • 原文地址:https://www.cnblogs.com/chenzheng8975/p/11156298.html
Copyright © 2011-2022 走看看