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>
  • 相关阅读:
    Shell中调用java时的参数
    简析echo命令在Linux系统中的使用
    设置Linux环境变量的三种方法
    nohup 后台运行,以及重定向标准输出和标准错误 &/dev/null 文件
    &命令
    linux下卸载gij的java
    在Linux下运行可执行Jar包
    jar参数运行应用时classpath的设置方法
    shell获取当前进程pid和上一个进程pid
    检查文件,如果文件不存在则创建
  • 原文地址:https://www.cnblogs.com/chenzheng8975/p/11156298.html
Copyright © 2011-2022 走看看