今天做的一个页面,要在scrollview中嵌套高德地图,产生触摸冲突,拖动地图和scrollview的滑动事件冲突。
先说一下最终的解决方案。亲测可用。。。
1、自定义一个viewGroup,继承Relativelayout(或者别的layout)
重点是重写了onInterceptTouchEvent(MotionEvent ev)和onTouchEvent(MotionEvent event)
/**
*解决地图在主scrollview中滑动冲突的问题由于MapView被定义成final class,所以只能在容器中操作了
Created by 苏七 on 2016/8/3
*/
public class MapContainer extends RelativeLayout {
private ScrollView scrollView;
public MapContainer(Context context) {
super(context);
}
public MapContainer(Context context, AttributeSet attrs) {
super(context, attrs);
}
public void setScrollView(ScrollView scrollView) {
this.scro

博客介绍了如何解决在ScrollView中嵌套高德地图时遇到的触摸冲突问题。通过自定义ViewGroup MapContainer,重写onInterceptTouchEvent和onTouchEvent方法,以及在代码中设置关联的ScrollView,可以实现地图滑动和ScrollView滑动的正常交互。
最低0.47元/天 解锁文章
760

被折叠的 条评论
为什么被折叠?



