解决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>

 

转载于:https://www.cnblogs.com/chenzheng8975/p/11156298.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值