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>
  • 相关阅读:
    vue学习03 v-html
    [spring guides]网关入门
    记一次公司mssql server密码频繁被改的事件
    重构 maixpy 的 board_info + config.json 从而自适应硬件版型。
    介绍 MaixUI 系列(一)如何食用?
    (旧文)在 micropython / esp-at / arduino 中实现 软串口(software-serial) 的参考
    以优化 MaixPy 的启动速度为例,说说 K210 的双核使用及原子操作。
    我是如何在 Win + VSCode 上开发 Keil for GD32 实现 I2C 从机的游戏机手柄。
    为 MaixPy 加入软 SPI 接口(移植 MicroPython 的 SPI)
    为 MaixPy 加入软 I2C 接口(移植 MicroPython 的 I2C)
  • 原文地址:https://www.cnblogs.com/chenzheng8975/p/11156298.html
Copyright © 2011-2022 走看看